开发者

bean reference with two Spring config context XML files

开发者 https://www.devze.com 2023-01-08 16:14 出处:网络
I always get it worked when reference to a bean in an other Spring context XML file but this time is doesn\'t work:

I always get it worked when reference to a bean in an other Spring context XML file but this time is doesn't work:

springapp-servlet.xml:

 <!-- Spring Controllers -->
<b:bean id="loginSpringController" class="com.foo.bar.controllers.spring.LoginController"/>
<b:alias name="loginSpringController" alias="loginSprController"/>   

application-context.xml

<!-- Custom AuthenticationProcessingFilter with Callbacks -->
<authentication-manager alias="authenticationManagerAlias"/>
<b:bean id="authentica开发者_StackOverflow中文版tionProcessingFilter" name="authenticationProcessingFilter" class="com.foo.bar.support.event.CustomAuthenticationProcessingFilter"> 
<b:property name="authenticationManager" ref="authenticationManagerAlias"/>
<b:property name="authenticationFailureUrl" value="/login.do?1=1"/>
<b:property name="filterProcessesUrl" value="/j_spring_security_check"/>
<b:property name="callback" ref="successfulAuthenticationCallbackImpl"/>
<b:property name="defaultTargetUrl" value="/index.html"/>
<!-- Reference to the sprint controller -->
<b:property name="loginSpringController"><b:ref bean="loginSprController"/></b:property>
<custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />          

But I still getting this error (even without the alias):

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'loginSprController' is defined


The beans in application-context.xml (which is "owned" by the webapp) cannot see the beans in springapp-servlet.xml (which is "owned" by the servlet). The servlets beans can see the webapp beans, however.

You need to rearrange your beans so that there are no references from application-context.xml to springapp-servlet.xml


It seems like what you are calling 'application-context.xml' should be renamed to 'springapp-security.xml'. Then it's more obvious why the spring controller bean should be moved to 'springapp-servlet.xml'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号