Announcement Announcement Module
No announcement yet.
Using bean from dispatcher-servlet.xml in security.xml Page Title Module
Move Remove Collapse
This topic is closed
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using bean from dispatcher-servlet.xml in security.xml

    Im wrote my own UserDetailsService. And I want inject my facade bean - which is describe in dispatcher-servlet.xml - to authority-provider in securityContext.xml.

    Can I do this some how?

    This not work but I show what kind of solution Im interesting.
        <beans:bean id="customUserDetailsService" class="">
            <beans:property name="facade" ref="facade" />
        <s:authentication-provider user-service-ref="customUserDetailsService" />
    and the problem is that in this context ( security ) the bean facade is not visible but in dispatcher work fine.

    Output of server
    ERROR org.springframework.web.context.ContextLoader  - Context initialization failed
    (...) .BeanCreationException: Error creating bean with name 'customUserDetailsService' defined in ServletContext resource [/WEB-INF/securityContext.xml]: Cannot resolve reference to bean 'facade' while setting bean property 'facade';

  • #2
    Beans in the Spring dispatcher-servlet application context are not normally visible to beans in the parent app context.


    • #3
      thanx for replay Luke
      I tried bind spring security and hibernate and my own data base schema with authorities and own user table.
      Maybe you can sugesst something instade of my approach with facade.

      In my dispatcher-servlet.xml I have
          <bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
             <property name="hibernateProperties">
                      <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                      <prop key="hibernate.connection.datasource">jdbc/nowoczesne_cc</prop>
      can I reDeclare something like this in Security context and if this make sens? This will be second bean like this but If there is no other way...

      I found this
      but Im not sure where dataSource bean is declared ? And probably in my case better way is to using hibernate some how but I dont know how and where.
      Please help me.
      Last edited by marcintom; May 21st, 2009, 09:05 AM.


      • #4
        the dispatcher-servlet.xml should only contain the web related stuff (viewresolvers, handlers, handlermappings etc.). Everything else should be loaded in the shared context. So simply move your LocalSessioNFactoryBean, your services, your daos to the root context.


        • #5
          Yes thx. Now I understand