0

我的项目使用 spring-mvc 框架。我一直遇到这个问题,每当我在heroku上部署应用程序时,它都会崩溃。我第一次部署它(这是我自己的项目,而不是 heroku 网站上提供的教程提供的示例),它运行良好。我最近所做的主要更改是添加了安全性和一些控制器。

Ps 整个应用程序在本地主机上运行时完美运行。

这是我在heroku上部署和运行时的日志:

H:\Documents-(H-drive)\FAST\Semester-8\ICC-Project\Spring-Workspace

\SpringHotelManagementSystem>heroku logs
2018-03-12T07:18:34.762170+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
2018-03-12T07:18:34.762171+00:00 app[web.1]:    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
2018-03-12T07:18:34.762173+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
2018-03-12T07:18:34.762175+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
2018-03-12T07:18:34.762177+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
2018-03-12T07:18:34.762179+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
2018-03-12T07:18:34.762187+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
2018-03-12T07:18:34.762189+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2018-03-12T07:18:34.762191+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2018-03-12T07:18:34.762193+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2018-03-12T07:18:34.762195+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:748)
2018-03-12T07:18:34.762197+00:00 app[web.1]: Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
2018-03-12T07:18:34.762201+00:00 app[web.1]:    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
2018-03-12T07:18:34.762199+00:00 app[web.1]:    at java.lang.ClassLoader.defineClass1(Native Method)
2018-03-12T07:18:34.762202+00:00 app[web.1]:    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
2018-03-12T07:18:34.762204+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
2018-03-12T07:18:34.762206+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
2018-03-12T07:18:34.762212+00:00 app[web.1]:    at java.lang.ClassLoader.defineClass1(Native Method)
2018-03-12T07:18:34.762210+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
2018-03-12T07:18:34.762226+00:00 app[web.1]:    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
2018-03-12T07:18:34.762208+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
2018-03-12T07:18:34.762228+00:00 app[web.1]:    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
2018-03-12T07:18:34.762230+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
2018-03-12T07:18:34.762232+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
2018-03-12T07:18:34.762234+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
2018-03-12T07:18:34.762235+00:00 app[web.1]:    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
2018-03-12T07:18:34.762237+00:00 app[web.1]:    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63)
2018-03-12T07:18:34.762239+00:00 app[web.1]:    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
2018-03-12T07:18:34.762241+00:00 app[web.1]:    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
2018-03-12T07:18:34.762243+00:00 app[web.1]:    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:237)
2018-03-12T07:18:34.762245+00:00 app[web.1]:    ... 32 more
2018-03-12T07:18:34.762247+00:00 app[web.1]:
2018-03-12T07:18:34.766868+00:00 app[web.1]: Mar 12, 2018 7:18:34 AM org.apache.catalina.core.StandardContext startInternal
2018-03-12T07:18:34.766871+00:00 app[web.1]: SEVERE: Error listenerStart
2018-03-12T07:18:34.815509+00:00 app[web.1]: Mar 12, 2018 7:18:34 AM org.apache.catalina.core.StandardContext startInternal
2018-03-12T07:18:34.815513+00:00 app[web.1]: SEVERE: Context [] startup failed due to previous errors
2018-03-12T07:18:34.848500+00:00 app[web.1]: SEVERE: Context [] failed in [org.apache.catalina.core.StandardContext] lifecycle. Allowing Tomcat to shutdown.
2018-03-12T07:18:34.851967+00:00 app[web.1]: Mar 12, 2018 7:18:34 AM org.apache.catalina.core.ApplicationContext log
2018-03-12T07:18:34.851970+00:00 app[web.1]: INFO: Closing Spring root WebApplicationContext
2018-03-12T07:18:34.852147+00:00 app[web.1]: INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Mon Mar 12 07:18:33 UTC 2018]; root of context hierarchy
2018-03-12T07:18:34.859280+00:00 app[web.1]: WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception thrown from ApplicationListener handling ContextClosedEvent
2018-03-12T07:18:34.859288+00:00 app[web.1]: java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Mon Mar 12 07:18:33 UTC 2018]; root of context hierarchy
2018-03-12T07:18:34.859291+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:337)
2018-03-12T07:18:34.859293+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
2018-03-12T07:18:34.859294+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1025)
2018-03-12T07:18:34.859297+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
2018-03-12T07:18:34.859298+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
2018-03-12T07:18:34.859300+00:00 app[web.1]:    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
2018-03-12T07:18:34.859302+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5035)
2018-03-12T07:18:34.859304+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5687)
2018-03-12T07:18:34.859305+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
2018-03-12T07:18:34.859307+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
2018-03-12T07:18:34.859309+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
2018-03-12T07:18:34.859311+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
2018-03-12T07:18:34.859313+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2018-03-12T07:18:34.859315+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2018-03-12T07:18:34.859316+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2018-03-12T07:18:34.859319+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:748)
2018-03-12T07:18:34.862763+00:00 app[web.1]: WARN : org.springframework.web.context.support.XmlWebApplicationContext - Exception thrown from LifecycleProcessor on context close
2018-03-12T07:18:34.862765+00:00 app[web.1]: java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Mon Mar 12 07:18:33 UTC 2018]; root of context hierarchy
2018-03-12T07:18:34.862767+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:350)
2018-03-12T07:18:34.862769+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1033)
2018-03-12T07:18:34.862771+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
2018-03-12T07:18:34.862773+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
2018-03-12T07:18:34.862775+00:00 app[web.1]:    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
2018-03-12T07:18:34.862776+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5035)
2018-03-12T07:18:34.862778+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5687)
2018-03-12T07:18:34.862780+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
2018-03-12T07:18:34.862782+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
2018-03-12T07:18:34.862783+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
2018-03-12T07:18:34.862785+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
2018-03-12T07:18:34.862787+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2018-03-12T07:18:34.862789+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2018-03-12T07:18:34.862791+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2018-03-12T07:18:34.862792+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:748)
2018-03-12T07:18:34.872554+00:00 app[web.1]: Mar 12, 2018 7:18:34 AM org.apache.catalina.core.StandardContext listenerStop
2018-03-12T07:18:34.872558+00:00 app[web.1]: SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
2018-03-12T07:18:34.872566+00:00 app[web.1]: java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
2018-03-12T07:18:34.872571+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1066)
2018-03-12T07:18:34.872572+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1040)
2018-03-12T07:18:34.872569+00:00 app[web.1]:    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
2018-03-12T07:18:34.872574+00:00 app[web.1]:    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:988)
2018-03-12T07:18:34.872576+00:00 app[web.1]:    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:586)
2018-03-12T07:18:34.872577+00:00 app[web.1]:    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
2018-03-12T07:18:34.872579+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5035)
2018-03-12T07:18:34.872581+00:00 app[web.1]:    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5687)
2018-03-12T07:18:34.872583+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
2018-03-12T07:18:34.872585+00:00 app[web.1]:    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
2018-03-12T07:18:34.872586+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
2018-03-12T07:18:34.872588+00:00 app[web.1]:    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
2018-03-12T07:18:34.872590+00:00 app[web.1]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2018-03-12T07:18:34.872592+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2018-03-12T07:18:34.872594+00:00 app[web.1]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2018-03-12T07:18:34.872596+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:748)
2018-03-12T07:18:34.872598+00:00 app[web.1]:
2018-03-12T07:18:34.958364+00:00 app[web.1]: Mar 12, 2018 7:18:34 AM org.apache.coyote.AbstractProtocol start
2018-03-12T07:18:34.958368+00:00 app[web.1]: INFO: Starting ProtocolHandler ["http-nio-34226"]
2018-03-12T07:18:35.009594+00:00 app[web.1]: INFO: Pausing ProtocolHandler ["http-nio-34226"]
2018-03-12T07:18:35.009587+00:00 app[web.1]: Mar 12, 2018 7:18:35 AM org.apache.coyote.AbstractProtocol pause
2018-03-12T07:18:36.206708+00:00 heroku[web.1]: Process exited with status 0
2018-03-12T07:18:36.233993+00:00 heroku[web.1]: State changed from up to crashed

这是我的 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.icc</groupId>
    <artifactId>springhms</artifactId>
    <name>SpringHotelManagementSystem</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- AWS SDK -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.11.289</version>
            <scope>compile</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                 </exclusion>
                 <exclusion>
                    <groupId>spring-asm</groupId>
                    <artifactId>spring-asm</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                 <exclusion>
                    <groupId>spring-asm</groupId>
                    <artifactId>spring-asm</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>   

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>        
    </dependencies>

    <build>

        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>copy</goal></goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.github.jsimone</groupId>
                                <artifactId>webapp-runner</artifactId>
                                <version>7.0.57.2</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        </plugins>
    </build>
</project>

这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml,/WEB-INF/spring-security.xml</param-value>

    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>



    <!-- Spring Security -->
    <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>
</web-app>

这是我的 spring-secruity.xml:

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    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/security
    http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <http auto-config="true">
        <intercept-url pattern="/admin/**" access="ROLE_ADMIN" />
        <intercept-url pattern="/client/**" access="ROLE_CLIENT" />

        <form-login
            login-page='/login.jsp'

            authentication-failure-url="/login.jsp" />
    </http>


    <authentication-manager>
      <authentication-provider>
        <user-service>
        <user name="admin1" password="123123" authorities="ROLE_ADMIN" />
        </user-service>
      </authentication-provider>
    </authentication-manager>

</beans:beans>

如果还有什么需要请告诉我。任何建议都会有所帮助。谢谢

4

0 回答 0