google Analytics

Monday, August 9, 2010

MDB Using SpringBeanAutowiringInterceptor EJB3.0 with JBOSS Example

=============================================================

=============================================================
@MessageDriven(
activationConfig = { @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination", propertyValue="testqueue")
})
@Interceptors(SpringBeanInterceptors.class)
public class TestMDB implements MessageListener {
public TestMDB() {
System.out.println("Inside TestMDB()");
}
@Autowired
private AnnotatedTarget target;

public void onMessage(Message message) {
System.out.println("onMessage-->>"+message);

}

}

=============================================================

=============================================================
==================================================================================================================================
public class SpringBeanInterceptors extends SpringBeanAutowiringInterceptor {

=============================================================

=============================================================
private static final String DEFAULT_RESOURCE_LOCATION = "classpath*:beanRefContext.xml";
@Override
protected BeanFactoryLocator getBeanFactoryLocator(Object target) {
System.out.println("Called BeanFactoryLocator2->>>>>>>>>>>>>>>>>>>>>>>>>>>>");
return ContextSingletonBeanFactoryLocator
.getInstance(DEFAULT_RESOURCE_LOCATION);
}

}
======================================================

==================================================================================================================================
public class AnnotatedTarget {
@Autowired
private Foo foo;
@Autowired
private Foo foo2;
@Autowired
private Bar bar;

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("AnnotatedTarget");
sb.append("{foo=").append(foo);
sb.append(", foo2=").append(foo2);
sb.append(", bar=").append(bar);
sb.append('}');
return sb.toString();
}
}
==================================================================================================================================

=============================================================

=============================================================
public class Bar {

@Override
public String toString() {
return getClass().getName();
}
}
==================================================================================================================================
public class Foo {

@Override
public String toString() {
return getClass().getName();
}
}

=============================================================

=============================================================
==================================================================================================================================
META-INF\SpringContext.xml
<?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">
<bean id="foo" class="com.apress.prospring2.ch03.autowiring.Foo"/>
<bean id="bar" class="com.apress.prospring2.ch03.autowiring.Bar"/>
<bean id="annotatedTarget" class="com.apress.prospring2.ch03.autowiring.AnnotatedTarget"/>
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>
==================================================================================================================================
--
in Ear folder outside META-INF
beanRefContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="beanfactoryTDS"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="META-INF/SpringContext.xml" />
</bean>
</beans>

=============================================================

=============================================================
==================================================================================================================================
Create EAR

Spring with ejb3.0
ANish

1 comment: