1

我正在尝试将 webflow 和安全配置添加到可操作的 Spring 3.1 MVC Web 应用程序中。

我摆脱了application-context.xml文件和ContextLoaderListener, 并AnnotationConfigWebApplicationContext与带@EnableWebMvc @Configuration注释的类一起使用。

然而,当我关注 webflow 和安全文档时,它似乎是一个application-context.xml文件并且ContextLoaderListener是必要的。后者似乎与AnnotationConfigWebApplicationContext.

任何人都可以提供一个简单但完整的 Spring 3.1 MVC Web 应用程序配置,带有 webflow 和启用安全性的示例吗?我正在寻找一个web.xml示例文件,以及任何其他必需的文件。

如果有人可以在线下载完整的示例应用程序,那就更好了。

4

1 回答 1

1

部署到 Tomcat 7 时,以下工作:

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"
    metadata-complete="false">

    <!-- Context Params -->
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.mypackage.web.WebConfig</param-value>
    </context-param>


    <!-- Filters --> 
    <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>

    <!-- Listeners -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Declaring and configuring the default Spring Servlet -->
    <servlet>

        <servlet-name>springExample</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <!-- Enabling annotation configuration for web app -->
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            </param-value>
        </init-param>

        <!-- Loading order -->
        <load-on-startup>1</load-on-startup>

    </servlet>

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

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>    

</web-app>

网络配置

@EnableWebMvc
@ImportResource({ "/WEB-INF/spring-security.xml", "/WEB-INF/spring-webflow.xml"})
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    // ...

}

警告:使用@Import(SomeConfig.class)不再起作用。它会导致初始化问题。解决方法是将内容移动SomeConfig.classWebConfig.class自身。

添加适当的 maven 依赖项很重要,否则,Tomcat 会导致 404 Resource not found 错误消息:

pom.xml

<properties>
    ...
    <spring.framework.version>3.1.2.RELEASE</spring.framework.version>
    <spring.security.version>3.1.1.RELEASE</spring.security.version>
    <spring.webflow.version>2.3.1.RELEASE</spring.webflow.version>
</properties>

<dependencies>
    ...
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.framework.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${spring.security.version}</version>
    </dependency> 
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency> 
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.1_3</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.webflow</groupId>
        <artifactId>spring-webflow</artifactId>
        <version>${spring.webflow.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.webflow</groupId>
        <artifactId>spring-binding</artifactId>
        <version>${spring.webflow.version}</version>
    </dependency>
</dependencies>
于 2012-07-23T12:37:55.153 回答