2015-04-03 65 views
0

這是我第一次在項目中使用Spring的經驗,我使用PrimeFaces和Hibernate,並且我還需要集成Spring安全性,事情是,在執行pom.xml配置之後,項目運行但PrimeFaces的「外觀和感覺」消失了,我不知道爲什麼會發生。PrimeFaces和Spring

,這裏是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.sebana</groupId> 
    <artifactId>sisafsebana</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <name>sisafsebana</name> 

    <properties> 
     <jdk.version>1.8</jdk.version> 
     <spring.version>4.0.1.RELEASE</spring.version> 
     <spring.security.version>4.0.1.RELEASE</spring.security.version> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 

     <!-- MySQL database driver --> 
<dependency> 
<groupId>mysql</groupId> 
<artifactId>mysql-connector-java</artifactId> 
<version>5.1.23</version> 
</dependency> 

     <dependency> 
      <groupId>org.primefaces</groupId> 
      <artifactId>primefaces</artifactId> 
      <version>5.0</version> 
     </dependency> 

     <!-- Spring 3 dependencies --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 

     <!-- Spring Security --> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-core</artifactId> 
      <version>4.0.0.RELEASE</version> 
     </dependency> 


     <dependency> 
      <groupId>org.glassfish.web</groupId> 
      <artifactId>javax.servlet.jsp.jstl</artifactId> 
      <version>1.2.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>4.3.1.Final</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate.javax.persistence</groupId> 
      <artifactId>hibernate-jpa-2.1-api</artifactId> 
      <version>1.0.0.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>7.0</version> 
      <scope>provided</scope> 
     </dependency> 

     <!-- Hibernate core --> 

     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>4.3.1.Final</version> 
     </dependency> 

     <!-- Hibernate core library dependecy start --> 
<dependency> 
<groupId>dom4j</groupId> 
<artifactId>dom4j</artifactId> 
<version>1.6.1</version> 
</dependency> 

<dependency> 
<groupId>commons-logging</groupId> 
<artifactId>commons-logging</artifactId> 
<version>1.1.1</version> 
</dependency> 

     <dependency> 
<groupId>commons-collections</groupId> 
<artifactId>commons-collections</artifactId> 
<version>3.2.1</version> 
</dependency> 

<dependency> 
<groupId>cglib</groupId> 
<artifactId>cglib</artifactId> 
<version>2.2</version> 
</dependency> 
<!-- Hibernate core library dependecy end --> 

     <!-- Hibernate query library dependecy start --> 
<dependency> 
<groupId>antlr</groupId> 
<artifactId>antlr</artifactId> 
<version>2.7.7</version> 
</dependency> 
<!-- Hibernate query library dependecy end --> 


<!-- Hibernate query library dependecy end --> 


    <!-- For Java EE Application Server, uncomment this library 
    and comment the rest of the libraries 
    <dependency> 
     <groupId>javax.faces</groupId> 
     <artifactId>jsf-api</artifactId> 
     <version>2.0</version> 
     <scope>provided</scope> 
    </dependency> 
    --> 

    <!-- For Servlet Container like Tomcat --> 
    <!-- http://download.java.net/maven/2 --> 
<dependency> 
<groupId>com.sun.faces</groupId> 
<artifactId>jsf-api</artifactId> 
<version>2.1.0-b03</version> 
</dependency> 
<dependency> 
<groupId>com.sun.faces</groupId> 
<artifactId>jsf-impl</artifactId> 
<version>2.1.0-b03</version> 
</dependency> 
<!-- EL 2.2 to support method parameter in EL --> 
    <dependency> 
<groupId>org.glassfish.web</groupId> 
<artifactId>el-impl</artifactId> 
<version>2.2</version> 
</dependency> 
    <!-- http://repo1.maven.org/maven2/ --> 
    <dependency> 
<groupId>javax.servlet</groupId> 
<artifactId>jstl</artifactId> 
<version>1.2</version> 
</dependency> 

<dependency> 
<groupId>javax.servlet</groupId> 
<artifactId>servlet-api</artifactId> 
<version>2.5</version> 
</dependency> 

<dependency> 
<groupId>javax.servlet.jsp</groupId> 
<artifactId>jsp-api</artifactId> 
<version>2.1</version> 
</dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
        <compilerArguments> 
         <endorseddirs>${endorsed.dir}</endorseddirs> 
        </compilerArguments> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.3</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.6</version> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>copy</goal> 
         </goals> 
         <configuration> 
          <outputDirectory>${endorsed.dir}</outputDirectory> 
          <silent>true</silent> 
          <artifactItems> 
           <artifactItem> 
            <groupId>javax</groupId> 
            <artifactId>javaee-endorsed-api</artifactId> 
            <version>7.0</version> 
            <type>jar</type> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
    <repositories> 
     <repository> 
      <url>http://repository.primefaces.org/</url> 
      <id>PrimeFaces-maven-lib</id> 
      <layout>default</layout> 
      <name>Repository for library PrimeFaces-maven-lib</name> 
     </repository> 
     <repository> 
      <id>unknown-jars-temp-repo</id> 
      <name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name> 
      <url>file:${project.basedir}/lib</url> 
     </repository> 
    </repositories> 
</project> 

我使用PrimeFaces 5.0

任何幫助將不勝感激

回答

1

我目前正在開發一個Tomcat服務器一個類似的項目。而我的POM(相關部分)是這樣的:

<dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tomcat</groupId> 
     <artifactId>tomcat-servlet-api</artifactId> 
     <version>8.0.18</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tomcat</groupId> 
     <artifactId>tomcat-el-api</artifactId> 
     <version>8.0.18</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.tomcat</groupId> 
     <artifactId>tomcat-jasper-el</artifactId> 
     <version>8.0.18</version> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-web-api</artifactId> 
     <version>${javax.javaee.web-api.version}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${org.springframework.webmvc.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.webflow</groupId> 
     <artifactId>spring-faces</artifactId> 
     <version>${org.springframework.faces.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.webflow</groupId> 
     <artifactId>spring-webflow</artifactId> 
     <version>${org.springframework.webflow.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.faces</groupId> 
     <artifactId>jsf-api</artifactId> 
     <version>${com.sun.faces.jsf.api.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.faces</groupId> 
     <artifactId>jsf-impl</artifactId> 
     <version>${com.sun.faces.jsf.implementation.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>se.jiderhamn</groupId> 
     <artifactId>classloader-leak-prevention</artifactId> 
     <version>${se.jiderhamn.classloader.leak.prevention.version}    </version> 
    </dependency> 
    <dependency> 
     <groupId>org.primefaces</groupId> 
     <artifactId>primefaces</artifactId> 
     <version>${org.primefaces.core.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.primefaces.extensions</groupId> 
     <artifactId>primefaces-extensions</artifactId> 
     <version>${org.primefaces.extensions.version}</version> 
    </dependency>` 

和我的web.xml看起來是這樣的:

<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_3_1.xsd" 
version="3.1"> 

<session-config> 
    <session-timeout>5</session-timeout> 
    <tracking-mode>COOKIE</tracking-mode> 
</session-config> 

<listener> 
    <description>Classloader leak check</description> 
    <listener-class>se.jiderhamn.classloader.leak.prevention.ClassLoaderLeakPreventor</listener-class> 
</listener> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<context-param> 
    <description>Spring Framework configuration location</description> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:configuration/spring/*-config.xml</param-value> 
</context-param> 
<context-param> 
    <param-name>com.sun.faces.expressionFactory</param-name> 
    <param-value>org.apache.el.ExpressionFactoryImpl</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.FACELETS_REFRESH_PERIOD</param-name> 
    <param-value>1</param-value> 
</context-param> 

<context-param> 
    <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name> 
    <param-value>true</param-value> 
</context-param> 
<context-param> 
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 
    <param-value>server</param-value> 
</context-param> 
<context-param> 
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name> 
    <param-value>true</param-value> 
</context-param> 
<context-param> 
    <param-name>com.sun.faces.numberOfViewsInSession</param-name> 
    <param-value>3</param-value> 
</context-param> 
<context-param> 
    <param-name>com.sun.faces.numberOfLogicalViews</param-name> 
    <param-value>1</param-value> 
</context-param> 
<context-param> 
    <param-name>com.sun.faces.allowTextChildren</param-name> 
    <param-value>true</param-value> 
</context-param> 

<filter> 
    <description>Spring character encoding filter</description> 
    <display-name>Spring character encoding filter</display-name> 
    <filter-name>CharacterEncodingFilter</filter-name> 
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
    <init-param> 
     <description>UTF-8 encoding</description> 
     <param-name>encoding</param-name> 
     <param-value>UTF-8</param-value> 
    </init-param> 
    <init-param> 
     <description>Force UTF-8</description> 
     <param-name>forceEncoding</param-name> 
     <param-value>true</param-value> 
    </init-param> 
</filter> 
<filter-mapping> 
    <filter-name>CharacterEncodingFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 
<servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>0</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
</servlet-mapping> 

<servlet> 
    <servlet-name>Spring MVC DispatcherServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value></param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>Spring MVC DispatcherServlet</servlet-name> 
    <url-pattern>/flow/*</url-pattern> 
</servlet-mapping> 

和我的faces-config.xml中看起來是這樣的:

<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_2.xsd" 
      version="2.2"> 
</faces-config> 

而你需要做的事情的最後兩個文件是一個基本模板:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui" 
xmlns:pe="http://primefaces.org/ui/extensions"> 

</html> 

並在其中包含模板的視圖頁面。同樣,這個版本被剝離,但如果你有任何問題,請隨時問:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition template="_basetemplate.xhtml"     xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui" 
xmlns:pe="http://primefaces.org/ui/extensions"> 
</ui:composition> 

正如你在我的觀點看,我包括我在其中定義了一些地區我的基本模板,但我認爲這是所有你需要做的事情。另外,我認爲你可以從你的pom.xml中排除這個依賴關係,因爲primefaces在xhtml中,而你並不真的需要jsps。

<dependency> 
<groupId>javax.servlet.jsp</groupId> 
<artifactId>jsp-api</artifactId> 
<version>2.1</version> 
</dependency> 

我使用Spring Webflow的,我並沒有在這裏包括配置,但是這是非常簡單的過了,再說,如果我錯過了什麼或你的奇蹟什麼,不要猶豫,問。