JBoss Community

Accessing spring beans that are deployed in a war.

created by Bas Ven in Snowdrop - View the full discussion

We are converting a huge Spring 3 based application to eventually be a JEE application using jBoss 7.1.1.Final.

As a first step we wrapped our application inside a war file which deploys inside jboss and works well.

I am trying to see if I can inject some of the spring beans inside this jar into a simple EJB. Both the war and EJB are packaged in an ear and I moved all jars from the war to the ear lib.

 

My war file has the META-INF/jboss-spring.xml file:

 

 

<?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>

 

and I see in the jboss log file at startup what looks like it is being read:

 

 

09:01:46,210 INFO  [org.jboss.spring.factory.NamedXmlApplicationContext] (MSC service thread 1-2) Refreshing org.jboss.spring.factory.NamedXmlApplicationContext@1daef240: startup date [Wed Jul 24 09:01:46 MDT 2013]; root of context hierarchy

09:01:46,211 INFO  [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-2) Loading XML bean definitions from "/content/assembly.ear/commander.war/META-INF/jboss-spring.xml"

09:01:46,217 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-2) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@330ec996: defining beans [dataSourceManager]; root of factory hierarchy

 

I try to inject this bean in my EJB as follows:

 

 

@Spring(bean = "dataSourceManager", jndiName = "Commander")

 

However when I try to call into my EJB I am getting a huge stacktrace that in the end tells me snowdrop couldn't find the 'Commander' factory:

 

 

Caused by: java.lang.IllegalStateException: javax.naming.NameNotFoundException: Commander -- service jboss.naming.context.java.jboss.Commander

    at org.jboss.spring.support.SpringInjectionSupport.lookup(SpringInjectionSupport.java:180) [snowdrop-deployers.jar:2.1.0.Final]

    at org.jboss.spring.support.SpringInjectionSupport.getObjectFromBeanFactory(SpringInjectionSupport.java:136) [snowdrop-deployers.jar:2.1.0.Final]

 

 

Any ideas?  Is this setup even supported or instead of wrapping our spring application inside a servlet should we 'just' make its jars avaliable and have some dummy EJB or sar start the application?

 

As a side note, I tried to build the sportsclub example but it can't find the jpl-util 1.0 (which is not avaliable on maven central); it also looks very outdated and I am wondering if there is a newer example distribution for snowdrop 2.x?

Reply to this message by going to Community

Start a new discussion in Snowdrop at Community