Updating to Spring Security 6.0 – replacing Removed and Deprecated functionality for securing requests

In Spring Security 6.0, antMatchers() as well as other configuration methods for securing requests (namely mvcMatchers() and regexMatchers()) have been removed from the API. An overloaded method requestMatchers() was introduced as a uniform mean for securing requests. The flavors of requestMatchers() facilitate all the ways of restricting requests that were supported by the removed methods. … Read more

How does Spring achieve IOC with autowiring?

First, and most important – all Spring beans are managed – they “live” inside a container, called “application context”. Second, each application has an entry point to that context. Web applications have a Servlet, JSF uses a el-resolver, etc. Also, there is a place where the application context is bootstrapped and all beans – autowired. … Read more

Spring Data MongoDB: how to implement “entity relationships”?

You can use the @DBRef annotation to persist the referenced class in a separate collection, else the document will be persisted in the same document (json). The use of DBRef require an extra query for the mongodb driver, you should consider this to analyze performance issues. From spring data documentation @DBRef – applied at the … Read more

Spring @Transactional(Propagation.NEVER) should create Hibernate session?

The behavior is correct – Hibernate will always create a session (how else would you expect it to perform any operation?), and by loading the entity you have associated it with that session. Since withoutTransaction is not participating in a transaction, the changes made within withTransaction will happen within a new transaction and shouldn’t be … Read more

How to manually render Spring MVC view to html?

Try autowiring the ViewResolver then calling resolveViewName(“myview”, Locale.US) to get the View. Then call render() on the view, passing it a “mock” HTTP response that has a ByteArrayOutputStream for its output, and get the HTML from the ByteArrayOutputStream. Update Here’s the working example, copied from the question. (so the code is actually with the answer) … Read more

Is anyone using SpringSource tc server as a Tomcat replacement?

As I see it, the primary advantage of tcServer is in managing large clusters of load-balanced tomcats. Aside from the management/monitoring layer (which is very cool, by the way), it also has a faster database connection pooling mechanism, and a generally tweaked configuration optimised for high volume. Other than that, it’s just Tomcat.

How to make a async REST with Spring?

The response body is blank because the @Async annotation is used at findEmail method of UserRepository class, it means that there is no data returned to the following sentence User user = userRepository.findByEmail(email); because findByEmail method is running on other different thread and will return null instead of a List object. The @Async annotation is … Read more