Spring JSF integration: how to inject a Spring component/service in JSF managed bean?

@ManagedBean vs @Controller First of all, you should choose one framework to manage your beans. You should choose either JSF or Spring (or CDI) to manage your beans. Whilst the following works, it is fundamentally wrong: @ManagedBean // JSF-managed. @Controller // Spring-managed. public class BadBean {} You end up with two completely separate instances of … Read more

Why does Spring MVC respond with a 404 and report “No mapping found for HTTP request with URI […] in DispatcherServlet”?

Your standard Spring MVC application will serve all requests through a DispatcherServlet that you’ve registered with your Servlet container. The DispatcherServlet looks at its ApplicationContext and, if available, the ApplicationContext registered with a ContextLoaderListener for special beans it needs to setup its request serving logic. These beans are described in the documentation. Arguably the most … Read more

Why is my Spring @Autowired field null?

The field annotated @Autowired is null because Spring doesn’t know about the copy of MileageFeeCalculator that you created with new and didn’t know to autowire it. The Spring Inversion of Control (IoC) container has three main logical components: a registry (called the ApplicationContext) of components (beans) that are available to be used by the application, … Read more

Spring + Hibernate manually creating transactions, PROPAGATION_REQUIRED fails. BUG?

You basically don’t use the transaction API as its intended to. The reference documentation is pretty precise about how to use programatic transactions: PlatformTransactionManager manager = … // obtain a transaction manager (DI) TransactionTemplate template = new TransactionTemplate(manager); template.execute(status -> { // Code to be execute in a transaction goes here. }); The important point … Read more