1

我正在尝试集成 Springsecurity、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 是正确的吗?问题

应用程序上下文.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>
4

1 回答 1

2

我想我明白...

我不是特别了解spring security。不考虑它,这是一般流程:

请求 -> struts2 解析并执行动作 -> 渲染视图(有时会是图块结果)

应将切片结果视为视图。Tiles 可以让您从视图中考虑共性,但归根结底,它只是一个视图。

使用 Spring Security 时,通常会保护 Web 应用程序中的每个 jsp 吗?如果不是,那么我也不会尝试保护瓷砖视图。

取而代之的是保护 struts2 动作......因为如果某些东西不安全,动作仍然会执行,并且可能会发生坏事。因此,阻止更高级别的“坏事”。

如果这是有道理的,那么您就不需要 applicationContext.xml 中的任何基于图块的东西(只需摆脱它)。错误当然是因为它无法解析类而发生的,但我有一种感觉,这个类真的是为 spring-mvc 集成而设计的,所以别管它了。

如果您遵循了 tiles3-plugin 集成指南,那么您的 web.xml 包含:

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

这将加载 struts2-tiles3 结果渲染所需的所有内容。

于 2013-05-09T03:37:25.523 回答