-
15. Re: Accessing spring beans that are deployed in a war.
jowilson Jul 25, 2013 8:03 PM (in response to batter)Were you able to get Sportsclub working? Would it be possible to see your code to help debug it? If not, can you post the stack trace?
-
16. Re: Accessing spring beans that are deployed in a war.
batter Jul 26, 2013 9:44 AM (in response to jowilson)I got sportsclub working after I went to github to get the latest version of it.
Like I said, I got past the stacktrace, it is just the the spring beans are always null although I know the beans I am asking for have been instantiated since my spring application is working fine:
@Spring(bean = "commanderServer", jndiName = "SpringCommander") private commander.server.CommanderServer commanderServer; public String getCommanderServer(){ String status = "Did not get a server object"; try { if ( commanderServer != null){ <== Always null status = "Hey I got something"; } } catch (Exception e) { status = e.getLocalizedMessage(); } return status; } One difference I have is that my EJB's live in one ear and the Spring beans in a separate war, each having their own jars. Not sure if this bean injection has a container (as in each ear, war etc) or JVM scope.
The spring beans are created in a java class that has the @Configuration annotation and the beans themselves are annotated with the @Bean annotation, like this:
@Configuration
public class MyConfiguration{
@Bean
public MyInterface MyBean(){
return new MyInterfaceImpl();
}
}
-
17. Re: Accessing spring beans that are deployed in a war.
jowilson Jul 26, 2013 10:50 AM (in response to batter)Which way are you trying to go Spring bean into EJB or EJB into Spring?
If are injecting a Spring Bean into an EJB Using Snowdrop then:
@Stateless
@Interceptors(SpringLifecycleInterceptor.class)
public class InjectedEjbImpl implements InjectedEjb {
@Spring(bean = "springBean", jndiName = "MyApp")
private SpringBean springBean;
}
OR if you are injecting an EJB Using Annotations then:
public class ConsumerBean {
@EJB(mappedName="ejb/exampleEJB")
ExampleEjb exampleEJB;
}
-
18. Re: Accessing spring beans that are deployed in a war.
tmehta Jul 26, 2013 6:27 PM (in response to jowilson)Just to make sure we attempted to deploy an ear with an ejb getting a spring injected by snowdrop from a *.spring deployment. The following was the configuration:
The EJB:
@Stateful
@Interceptors({SpringLifecycleInterceptor.class})
public class GreeterEJB implements IGreeterEJB {
@Spring(bean = "springBean", jndiName = "MyApp")
private Object memberDao;
/** rest of class **/
}
In the ear pom.xml:
Note scope is not set to provided:
<dependency>
<groupId>org.jboss.snowdrop</groupId
<artifactId>snowdrop-deployers-core</artifactId>
<version>2.1.1.SNAPSHOT</version>
</dependency>
Content of resources/META-INF/jboss-deployment-structure.xml:
Make sure this at the top level of the ear.
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<dependencies>
<module name="org.springframework.spring" slot="snowdrop" export="true">
<exports>
<include path="META-INF**"/>
<include path="org**"/>
</exports>
<imports>
<include path="META-INF**"/>
<include path="org**"/>
</imports>
</module>
<module name="org.jboss.snowdrop" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
In META-INF/jboss-spring.xml of either the ear top level or a seperate *.spring application:
<?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">
<description>BeanFactory=(MyApp)</description>
/** beans or imports etc. **/
</beans>
Hopefully this helps you out. If not I can send over this sample working solution (much smaller than sporstclub) and hopefully you can take it from there.
Cheers,
Tejas M.