Activating CDI in JSF 2.3
$ mvn archetype:generate -DgroupId=com.example -DartifactId=demo -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false<properties> <version.javaee-api>8.0</version.javaee-api> ...// other properties </properties> <dependencyManagement> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>${version.javaee-api}</version> <scope>provided</scope> </dependency> ...//other dependencies </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> </dependency> ...//other dependencies </dependencies><?xml version='1.0' encoding='UTF-8'?> <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd" version="2.3"> </faces-config><?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd" bean-discovery-mode="all" version="2.0"> </beans><?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <context-param> <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name> <param-value>0</param-value> </context-param> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> <context-param> <param-name>javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name> <param-value>true</param-value> </context-param> <!-- <context-param> <param-name>javax.faces.DISABLE_FACESSERVLET_TO_XHTML</param-name> <param-value>true</param-name> </context-param>--> </web-app>@FacesConfig( // Activates CDI build-in beans version = JSF_2_3 ) public class ConfigurationBean { }@Qualifier @Target(TYPE) @Retention(RUNTIME) public @interface FacesConfig { public static enum Version { /** * <p class="changed_added_2_3">This value indicates CDI should be used * for EL resolution as well as enabling JSF CDI injection, as specified * in Section 5.6.3 "CDI for EL Resolution" and Section 5.9 "CDI Integration".</p> */ JSF_2_3 } /** * <p class="changed_added_2_3">The value of this attribute indicates that * features corresponding to this version must be enabled for this application.</p> * @return the spec version for which the features must be enabled. */ @Nonbinding Version version() default Version.JSF_2_3; }
Last updated