Announcement Announcement Module
No announcement yet.
Problem accessing spring beans Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem accessing spring beans

    Good day,

    Quick insight of the flow:

    Intranet Client -->(invokes) Application --> (get credentials) NTLM using Servlets --> (forwards to action) Struts using Spring -->(get modules from Jboss container) JAAS using Jboss -->(invokes) LoginModule in WAR --> uses components defined in Spring inside the same WAR

    LoginModule in WAR --> uses components defined in Spring inside the same WAR

    although struts has access to beanFactory, which is invoked via struts plugin

    how do my LoginModule inside the same WAR will have access to Spring beanFactory as it has been invoked by Jboss container.

    pllzzzz help i have been striving to get this working.

  • #2
    beanRefFactory.xml under WEB-INF directory

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "">
    <bean id="" lazy-init="true" class=" thXmlApplicationContext">

    and spring-config.xml is under WEB-INF\spring
    contains the following

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
    <beans default-lazy-init="false">

    <bean class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator" />

    <import resource="logger/log-config.xml"/>
    <import resource="ibatis/ibatis-config.xml"/>
    <import resource="struts/struts-config-1.xml"/>
    <import resource="aop/aop-config.xml"/>
    <import resource="component/component-config.xml"/>
    <import resource="business/business-config.xml"/>
    <import resource="jaas/jaas-module-config.xml"/>

    </beans> under the same WAR but is invoked by JBoss

    and my initialize() method of JAAS is as follows
    public void initialize(Subject subject, CallbackHandler callbackHandler, Map<java.lang.String, ?> sharedState, Map<java.lang.String, ?> options) {
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;
    // initialize any configured options
    debug = "true".equalsIgnoreCase((String)options.get("debug "));

    // Accessing Spring bean from non spring context
    BeanFactoryLocator beanFactoryLocator = SingletonBeanFactoryLocator.getInstance();
    BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("") ;
    beanFactory = beanFactoryReference.getFactory();

    i am not able to get the bean factory inside this method. all the above files are under the same war.


    • #3
      observations: it is looking for beanRefFactory.xml under conf directory of Jboss. i put the file under conf directory and got the following

      21:03:46,546 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from URL [vfsfile:/C:/jboss-5.1.0.GA/server/default/conf/beanRefFactory.xml]
      21:03:46,656 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in [email protected]: defining beans []; root of factory hierarchy
      21:03:46,984 INFO [ClassPathXmlApplicationContext] Refreshing [email protected]: display name [ [email protected]]; startup date [Fri Aug 28 21:03:46 IST 2009]; root of context hierarchy
      21:03:47,000 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [spring/spring-config.xml]
      21:04:08,359 ERROR [STDERR] Authentication failed:
      21:04:09,218 ERROR [STDERR] org.springframework.beans.factory.access.Bootstrap Exception: Unable to return specified BeanFactory instance: factory key [], from group with resource name [classpath*:beanRefFactory.xml]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '' defined in URL [vfsfile:/C:/jboss-5.1.0.GA/server/default/conf/beanRefFactory.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [ plicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [spring/spring-config.xml]; nested exception is class path resource [spring/spring-config.xml] cannot be opened because it does not exist
      at org.springframework.beans.factory.access.Singleton BeanFactoryLocator.useBeanFactory(SingletonBeanFac
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at own Source)
      at$000( Unknown Source)
      at$ wn Source)
      at Method)
      at Unknown Source)
      at wn Source)
      at ava:40)
      at :135)
      at 116)

      i understand the above error is because, it is looking for spring/spring-config.xml under conf directory.

      is there any way that while creating the beanFactoryLocator i can specify the jar/war file location, be default it looks for beanRefFactory.xml under the directory from where the class is invoked, but if i able to refer beanRefFactory.xml under osaWeb.war \WEB-INF directory. i should be able to get the references of the beans, i guess. plz correct me if i am wrong.