【问题标题】:Java config in Spring with AOP使用 AOP 在 Spring 中进行 Java 配置
【发布时间】:2016-05-16 06:15:36
【问题描述】:

这个问题是关于 Spring 中的 Java 配置。是否可以在 Java 代码中替换以下声明。

<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/secure-app-context.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

其中secure-app-context.xml

  <beans xmlns="http://www.springframework.org/schema/beans"
    ...
    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

    <aop:aspectj-autoproxy />

    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
        <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
            </mvc:message-converters>
        </mvc:annotation-driven> 

        <context:component-scan base-package="com.abc.secure.service" />

        <bean id="securityAspect" class="com.abc.secure.service.Secure" />
    </beans>

【问题讨论】:

  • 是的,可以在 Java 代码中替换以下声明。

标签: spring spring-security


【解决方案1】:

使用 WebApplicationInitializer 可以很好地做到这一点(在这种情况下你不需要 web.xml)

请看下面的帖子:

How to configure Spring MVC with pure Java-based configuration?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-26
    • 2016-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 2012-11-04
    相关资源
    最近更新 更多