Skip to content

Instantly share code, notes, and snippets.

@didyhu
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save didyhu/9775268 to your computer and use it in GitHub Desktop.
Save didyhu/9775268 to your computer and use it in GitHub Desktop.
JSF as MVC + Spring as IOC Container

JSF as MVC + Spring as IOC Container

Context

  • About
  • Configuration
  • Optional

About

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.

Configuration

  1. Create a standard web MAVEN project.

  2. 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>
  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment