1

According to this answer, I set up JSF on Spring Boot. The problem is, that the embedded Tomcat does not scan the @ManagedBean annotations at startup.

For testing, I placed this ManagedBean:

@javax.faces.bean.ManagedBean(eager = true)
@javax.faces.bean.ApplicationScoped
public class TestController {

 public TestController() {
    System.out.println("Eager ManagedBean!");
 }
}

The JSF servlet is initialized correctly (and eagerly) at startup, but the sout text is not printed:

INFO [config] - Mojarra 2.2.13 für Kontext '' wird initialisiert.
INFO [PostConstructApplicationEventListener] - Running on PrimeFaces 6.0
INFO [config]- Monitoring file:/src/main/webapp/WEB-INF/faces-config.xml for modifications

I have also placed a faces-config.xml in WEB-INF, having 'metadata-complete=false'.

I think it might have something to do with the way the embedded Tomcat is configured, maybe Tld scan? I did not change the Spring Boot default Tomcat.

Can someone tell me how to enable annotation scanning in embedded Tomcat 8?

Community
  • 1
  • 1
Stefan
  • 12,108
  • 5
  • 47
  • 66
  • Instead of manual setup have you tried [this](https://github.com/joinfaces/joinfaces) that uses auto configuration. – M. Deinum Oct 07 '16 at 10:43
  • Ty, I have tried that (and it actually works, if I change @ManagedBean to @Named), but I already have a partent pom and it seems that I can't import 'jsf-spring-boot-parent'. – Stefan Oct 07 '16 at 11:50
  • `@Named` will make the bean detected by Spring and hence a spring managed bean, I guess due to the fact that you have JSF / Spring integration setup it appears to work. You don't have to use a parent (why do people always think that the sample is the only way to go?). You can also add it to `dependencyManagement` as a `bom` (at least that should be possible) and `import` it. – M. Deinum Oct 07 '16 at 11:57
  • The import using dependencyManagement worked, but If they become Spring-managed, I cant use the Jsf scope annotation anymore, which is the reason for me to search for managedBean scanning. The beans can also be configured to work with Spring by annotationg them with Component, so you can avoid this import, but thanks anyway. – Stefan Oct 07 '16 at 12:07
  • They only become spring managed if you add `@Named` which in turn doesn't work with JSF scopes you will have to use CDI scopes then and making CDI and Spring Work together is a whole different story!. Use `@ManagedBean` that should work (at least it worked for me a year ago). – M. Deinum Oct 10 '16 at 06:12
  • @Stefan were you able to make your spring boot JSF 2.0 app work with JSF annotations like ManagedBean. I have a similar issue mentioned at https://stackoverflow.com/questions/72811623/spring-boot-2-7-1-integration-with-jsf-2-2-mojarra-and-primefaces-6-2-9 – Jacob Jul 01 '22 at 05:41
  • There is a framework for integrating JSF into Spring Boot. Have a look, it helped me too: http://joinfaces.org/ – Stefan Jul 01 '22 at 17:26

0 Answers0