- About
- Configuration
- Optional
It' about to build a java web project using JSF as MVC, and Spring as a bean IOC container.
It can be a alternative way to use standard Java EE container. It's lighter than common Java EE container, and it is compatible to most Java EE standards.
-
Create a standard web MAVEN project.
-
Modify the pom.xml.
<!-- jsf -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>RELEASE</version>
</dependency>
<!-- inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>RELEASE</version>
</dependency>
<!-- primefaces optional -->
<!--
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>RELEASE</version>
</dependency>
-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!-- spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
- Modify web.xml. If there is not, create one in /src/main/webapp/WEB-INF
<!-- spring -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- jsf -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Servlet 3.0+ supports configuration without web.xml, here it uses web.xml for backward compatible to elder Server.