【问题标题】:spring Autowired Environment弹簧自动装配环境
【发布时间】:2014-07-08 20:36:41
【问题描述】:

我试图从属性文件中获取一个简单的值。它适用于我的 SpringMVC 类,但不适用于我的 SavedRequestAwareAuthenticationSuccessHandler 类。

在我定义的 spring-servlet.xml 中:

<context:property-placeholder location="file:/TcatServer6/myapp/properties/myapp/myapp.properties" />

在我的代码中:

@Value("${anotherapp_url}")
private String anotherAppURL;

@Autowired
private Environment environment;

在我的 Spring MVC 控制器中,这些工作正常。在我的 spring 安全登录处理程序中,这是一个扩展 SavedRequestAwareAuthenticationSuccessHandler 的类,它们都返回 null。这是我的 spring-security.xml

<beans:bean id="adsh" class="com.cs.mytime.agentdesktop.security.ADAuthenticationSuccessHandler"/>

<http auto-config="true">
    <intercept-url pattern="/agent/**" access="ROLE_AGENT" />
    <form-login
        login-page="/r/views/login.html"
        authentication-failure-url="/r/views/loginfailed.html"
        authentication-success-handler-ref="adsh"
    />
    <logout logout-success-url="/logout" />
</http>

我已经阅读了互联网上的大量内容,但这始终为空,似乎无法使其正常工作。没有意义。

【问题讨论】:

  • spring-security.xml 是如何被引导的?它是否包含在其他文件中?

标签: spring spring-mvc properties spring-security autowired


【解决方案1】:

BeanFactory(Post)Processors 仅在定义它们的上下文中运行。

spring-servlet.xml 中定义的&lt;context:property-placeholder .. /&gt;spring-security.xml 中的bean 没有任何作用。因为第一个由DispatcherServlet 加载,而第二个由ContextLoaderListener 加载。

恐怕你必须声明两次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    相关资源
    最近更新 更多