2013-05-09 71 views
1

我想集成Springsecurity,struts2和tiles3,一旦我運行我的應用程序,它會遇到以下錯誤,請讓我知道如果我應該包含我的代碼的任何其他部分。如何集成Spring-security,struts2和tiles3

Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.view.tiles3.tilesConfigurer] for bean with name 'tilesConfigurer' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.tiles3.tilesConfigurer. Please see server.log for more details. 
The module has not been deployed. 
See the server log for details. 
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:210) 
    at org.netbeans.modules.maven.j2ee.ExecutionChecker.performDeploy(ExecutionChecker.java:178) 
    at 
    org.netbeans.modules.maven.j2ee.ExecutionChecker.executionResult(ExecutionChecker.java:130) 
    at 
    org.netbeans.modules.maven.execute.MavenCommandLineExecutor.run(MavenCommandLineExecutor.java:212) 
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153) 

根據這個問題Spring不支持Tiles3是否正確? Question

的applicationContext.xml

<?xml version='1.0' encoding='UTF-8'?> 
    <beans xmlns='http://www.springframework.org/schema/beans' 
        xmlns:context='http://www.springframework.org/schema/context' 
        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
        xsi:schemaLocation='http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/context  
     http://www.springframework.org/schema/context/spring-context-3.0.xsd'> 

     <context:component-scan base-package='com.MyProject'/> 
     <bean id='internalResourceResolver' 
        class='org.springframework.web.servlet.view.InternalResourceViewResolver'> 
      <property name='prefix' value='/Web Pages/'/> 
      <property name='suffix' value='.jsp'/> 
     </bean> 
     <bean 
     class='org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping'/> 
     <bean 
     class='org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'/> 
     <bean id='placeholderConfig' 

      class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'/> 

     <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass"> 
      <value> 
       org.springframework.web.servlet.view.tiles3.tileviewresolver 
      </value> 
     </property> 
    </bean> 
     <bean id="tilesConfigurer" 
      class="org.springframework.web.servlet.view.tiles3.tilesConfigurer"> 
     <property name="definitions"> 
      <list> 
       <value>/WEB-INF/tiles.xml</value> 
      </list> 
     </property> 
    </bean> 
    </beans> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web- 
    app_3_0.xsd"> 
     <context-param> 
      <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name> 
      <param-value>/WEB-INF/tiles.xml</param-value> 
     </context-param> 
     <listener> 
     <listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener- 
     class> 
     </listener> 
      <listener> 
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener- 
       class> 
     </listener> 
     <context-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value> 
       /WEB-INF/applicationContext.xml 
       /WEB-INF/myProject-security.xml 
       /WEB-INF/login-service.xml 
      </param-value> 
     </context-param> 
     <filter> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <filter-class> 
       org.springframework.web.filter.DelegatingFilterProxy 
      </filter-class> 
     </filter> 

     <filter-mapping> 
      <filter-name>springSecurityFilterChain</filter-name> 
      <url-pattern>/*</url-pattern> 
     </filter-mapping> 
     <filter> 
      <filter-name>struts2</filter-name> 
      <filter-  
     class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter- 
      class> 
     </filter> 
     <filter-mapping> 
      <filter-name>struts2</filter-name> 
      <url-pattern>/*</url-pattern> 
     </filter-mapping> 
     <session-config> 
      <session-timeout> 
       30 
      </session-timeout> 
     </session-config> 
     <welcome-file-list> 
      <welcome-file>index.jsp</welcome-file> 
     </welcome-file-list> 
    </web-app> 

的pom.xml

<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.myproject</groupId> 
    <artifactId>MyProject</artifactId> 
    <version>1.0</version> 
    <packaging>war</packaging> 

    <name>MyProject</name> 

    <properties> 
     <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <glassfish.embedded-static-shell.jar>C:\Program 
     Files\Java\jre7\bin\glassfish\lib\embedded\glassfish-embedded-static- 
     shell.jar</glassfish.embedded-static-shell.jar> 
     <netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-core</artifactId> 
      <version>2.3.8</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-fileupload</groupId> 
      <artifactId>commons-fileupload</artifactId> 
      <version>1.2.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>jsp-2.1-glassfish</artifactId> 
      <version>9.1.02.B04.p0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-convention-plugin</artifactId> 
      <version>2.3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-dojo-plugin</artifactId> 
      <version>2.3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts-taglib</artifactId> 
      <version>1.3.10</version> 
     </dependency> 
     <dependency> 
      <groupId>jdbc</groupId> 
      <artifactId>jdbc-stdext</artifactId> 
      <version>2.0</version> 
      <type>pom</type> 
     </dependency> 
     <dependency> 
      <groupId>javax.sql</groupId> 
      <artifactId>jdbc-stdext</artifactId> 
      <version>2.0</version> 
      <type>pom</type> 
     </dependency> 
     <dependency> 
      <groupId>org.glassfish.extras</groupId> 
      <artifactId>glassfish-embedded-static-shell</artifactId> 
      <version>3.1.1</version> 
      <scope>system</scope> 
      <systemPath>${glassfish.embedded-static-shell.jar}</systemPath> 
     </dependency> 
     <dependency> 
      <groupId>com.kenai.nbpwr</groupId> 
      <artifactId>org-apache-commons-dbcp</artifactId> 
      <version>1.2.2-201002241055</version> 
      <type>nbm</type> 
     </dependency> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.24</version> 
     </dependency> 
      <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>3.0.7.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>3.0.7.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-core</artifactId> 
      <version>3.0.7.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-taglibs</artifactId> 
      <version>3.0.7.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>3.0.7.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-dbutils</groupId> 
      <artifactId>commons-dbutils</artifactId> 
      <version>1.5</version> 
      <type>jar</type> 
     </dependency> 
     <dependency> 
      <groupId>struts</groupId> 
      <artifactId>struts</artifactId> 
      <version>1.2.9</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.taglibs</groupId> 
      <artifactId>taglibs-parent</artifactId> 
      <version>3</version> 
      <type>pom</type> 
     </dependency> 
     <dependency> 
      <groupId>com.itextpdf</groupId> 
      <artifactId>itextpdf</artifactId> 
      <version>5.3.2</version> 
     </dependency> 
     <dependency> 
      <groupId>com.google.zxing</groupId> 
      <artifactId>javase</artifactId> 
      <version>1.7</version> 
     </dependency> 
     <dependency> 
      <groupId>com.google.zxing</groupId> 
      <artifactId>core</artifactId> 
      <version>1.7</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.xml</groupId> 
      <artifactId>jaxrpc</artifactId> 
      <version>1.1</version> 
      <type>pom</type> 
     </dependency> 
     <dependency> 
      <groupId>taglibs</groupId> 
      <artifactId>fmt</artifactId> 
      <version>1.1.2</version> 
      <type>tld</type> 
     </dependency> 
     <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     <version>1.8.0</version> 
     </dependency> 
     <dependency> 
    <groupId>commons-digester</groupId> 
    <artifactId>commons-digester</artifactId> 
    <version>2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>1.3.2</version> 
     </dependency> 
     <dependency> 
      <groupId>net.sf.opencsv</groupId> 
      <artifactId>opencsv</artifactId> 
      <version>2.3</version> 
      <type>jar</type> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-tiles3-plugin</artifactId> 
      <version>2.3.14</version> 
     </dependency> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>6.0</version> 
      <type>jar</type> 
     </dependency> 
     <dependency> 
      <groupId>axis</groupId> 
      <artifactId>axis</artifactId> 
      <version>1.4</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-discovery</groupId> 
      <artifactId>commons-discovery</artifactId> 
      <version>0.2</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
      <version>1.1.1</version> 
     </dependency> 
      <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.5.6</version> 
     </dependency> 
    <dependency> 
<groupId>log4j</groupId> 
<artifactId>log4j</artifactId> 
<version>1.2.15</version> 
<exclusions> 
    <exclusion> 
     <groupId>com.sun.jmx</groupId> 
     <artifactId>jmxri</artifactId> 
    </exclusion> 
    <exclusion> 
     <groupId>com.sun.jdmk</groupId> 
     <artifactId>jmxtools</artifactId> 
    </exclusion> 
    <exclusion> 
      <groupId>javax.jms</groupId> 
      <artifactId>jms</artifactId> 
    </exclusion> 
</exclusions> 
</dependency> 
      <dependency> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-api</artifactId> 
    <version>1.5.6</version> 
</dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <compilerArguments> 
         <endorseddirs>${endorsed.dir}</endorseddirs> 
        </compilerArguments> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.1.1</version> 
       <configuration> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-dependency-plugin</artifactId> 
       <version>2.1</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>6.0</version> 
            <type>jar</type> 
           </artifactItem> 
          </artifactItems> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 

</project> 

回答

2

我想我明白了...

我不是特別瞭解春季安全。不考慮它,這是一般的流程:

請求 - > struts2的解析和執行動作 - >呈現視圖(其將有時是瓦片結果)

甲瓷磚的結果應該被認爲是一個視圖。瓷磚可以讓你將意見排除在意見之外,但在一天結束時,它只是一個視圖。

當使用spring安全性時,通常在Web應用程序中保護每個jsp? 如果不是那麼我不會嘗試保證瓷磚視圖。

取而代之的是確保struts2的動作...因爲如果某些東西不安全,動作仍然會執行,並且可能會發生不好的事情。因此,阻止鏈條上的「壞事」。

如果這是有道理的,那麼你不需要applicationContext.xml中的任何基於圖塊的東西(只是擺脫它)。當然這個錯誤是因爲它無法解決課程而發生的,但我有一種感覺,這個課程真的是用於spring-mvc集成,所以只是忘了它。

如果按照tiles3-插件集成指南那麼你的web.xml文件中包含:

<listener> 
    <listener-class>org.apache.tiles.extras.complete.CompleteAutoloadTilesListener</listener-class> 
</listener> 

這將加載所需的struts2-tiles3結果呈現的一切。

+0

它現在的作品,現在我應該打開一個新的問題菜單的東西? – J888 2013-05-09 03:45:29

+0

對不起,是的。評論太短...迪斯科。 – Quaternion 2013-05-09 03:55:43

+0

好的新問題在這裏http://stackoverflow.com/questions/16454135/how-to-provide-different-menu-according-to-rule-of-user – J888 2013-05-09 04:03:00