JBoss Community

Re: Accessing spring beans that are deployed in a war.

created by Bas Ven in Snowdrop - View the full discussion

Ok, getting furhter once again.  The problem about the BeanFactory not being registered was due to the fact that your jboss-spring.xml definition has changed from the examples I found on the site to what is actually needed.

As posted before, I had this defined as:

 

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

 

<beans>

 

    <description>BeanFactory=(Commander)</description>

    <bean id="dataSourceManager" class="database.DataSourceManagerImpl" />

</beans>

 

 

I looked thru some of the newer source and noticed that you defined them differently and I updated my jboss-spring.xml file to reflect that change:

 

 

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd" default-lazy-init="true">

 

    <description>BeanFactory=(SpringCommander)</description>

    <bean id="dataSourceManager" class="com.electriccloud.database.DataSourceManagerImpl" />

    <bean id="commanderServer" class="com.electriccloud.commander.server.CommanderServerImpl" />

 

</beans>

 

 

Now when I look in the jBoss console I indeed see that the factory is registered with JNDI.

 

However I still get an exception when I actually try to have the spring bean injected in my EJB and I hope you can help me out there.  This is the exception:

java.lang.IllegalArgumentException: Cannot retrieve an org.springframework.beans.factory.BeanFactory from java:jboss/SpringCommander - a org.jboss.spring.factory.NamedXmlApplicationContext found instead

org.jboss.spring.support.SpringInjectionSupport.lookup(SpringInjectionSupport.java:175)

org.jboss.spring.support.SpringInjectionSupport.getObjectFromBeanFactory(SpringInjectionSupport.java:136)

org.jboss.spring.support.SpringInjectionSupport.injectToField(SpringInjectionSupport.java:202)

org.jboss.spring.support.SpringInjectionSupport.inject(SpringInjectionSupport.java:80)

org.jboss.spring.callback.SpringLifecycleInterceptor.postConstruct(SpringLifecycleInterceptor.java:43)

Reply to this message by going to Community

Start a new discussion in Snowdrop at Community