In a simple JSF 2.2 project using Mojarra. There is a managed bean:
@RequestScoped
@Named(value="myHello")
public Hello {
private String name = "test";
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
and this managed bean is used in a jsf with placeholder #{myHello.name}
. In order to make the CDI work, weld 3.1.3 Final (CDI 2.0 implementation) is added as dependency
The compiled war is deployed to a Tomcat 8 servlet container.
Unexpected result: the JSF can be displayed fluently, but #{myHello.name}
didn't ouput test
as expected but nothing
The ogirinal solution was add an empty beans.xml to WEB-INF directory according to the answer in How to install and use CDI on Tomcat?, and it indeed can work out this problem.
But being that the note in Weld 3.1.3 Final specification:
The
beans.xml
file is no longer required for CDI enablement as of CDI 1.1. CDI is automatically enabled for archives which don’t containbeans.xml
but contain one or more bean classes with a bean defining annotation
An empty beans.xml
would not be necessary any more.
Question:
- Why is an empty
beans.xml
still compulsory? - How to make the placeholder
#{myHello.name}
work properly without an emptybeans.xml
?