google Analytics

Sunday, August 29, 2010

EJB 3.0 with Spring 1.2 SpringBeanAutowiringInterceptor

ejb3 Spring

The EJB
EJB3-compliant interceptor class that injects Spring beans into fields

and methods which are annotated with @Autowired. Performs injection after
construction as well as after activation of a passivated bean.
To be applied through an @Interceptors annotation in the

EJB Session Bean
or Message-Driven Bean class, or through an interceptor-binding XML
element in the EJB deployment descriptor.
Delegates to Spring's AutowiredAnnotationBeanPostProcessor underneath,
allowing for customization of its specific settings through overriding
the configureBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor,
java.lang.Object) template method.
The actual BeanFactory to obtain Spring beans from is determined by the getBeanFactory(java.lang.Object)
template method. The default implementation obtains the Spring ContextSingletonBeanFactoryLocator,
initialized from the default resource location classpath*:beanRefContext.xml,
and obtains the single ApplicationContext defined there


package com.test;

import javax.ejb.Stateless;
import javax.interceptor.Interceptors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

import com.test.TestSpringBeanAutoWiringSessionBean;

@Interceptors(SpringBeanAutowiringInterceptor.class)
public @Stateless class TestSpringBeanAutoWiringSessionBeanBean implements TestSpringBeanAutoWiringSessionBean {
    @Override
    public void sayHello(String name) {
        System.out.println("Anish---->>"+name);
    }
   
    @Autowired
    private AnnotatedTarget target;
}

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

and here' smy SpringContext.xml
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>

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();
}
}

Technology Solutions: MDB Using SpringBeanAutowiringInterceptor ...

MDB USING Spring Bean Autowiring Interceptor
http://opensourceframework.blogspot.com/2010/08/mdb-using-springbeanautowiringintercept.html



EJB 3.0 with Spring 1.2
SpringBeanAutowiringInterceptor Spring2.5.2 API



3 comments:

  1. TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
    Check out the best
    shoe storage nz
    outdoor furniture covers nz
    body pillow nz

    ReplyDelete