Hi
This works:
@Remote @Stateless @WebService public class CalculatorService1 implements Calculator { @WebMethod public int add(int a, int b) { Calculator c = new CalculatorImpl(); int result = c.add( a, b ); return result; } }
@Remote @Stateless @WebService public class CalculatorService2 implements Calculator { private static final String SPRING_FILE = "calc.xml"; private static final String CALC_BEAN = "calculator"; private Calculator c = null; private Log log; public CalculatorService2() { log = LogFactory.getLog( getClass() ); log.info("Constructor"); } @WebMethod public int add(int a, int b) { log.info("Request for adding " + a + " + " + b ); int result = c.add( a, b ); return result; } @PostActivate public void postActivate() { log.info("Post activate"); InputStream is = getClass().getClassLoader().getResourceAsStream( SPRING_FILE ); InputStreamResource isr = new InputStreamResource( is ); XmlBeanFactory bf = new XmlBeanFactory( isr ); c = (Calculator) bf.getBean( CALC_BEAN ); } @PrePassivate public void prePassivate() { log.info("Pre passivate"); c = null; } }
Hi!
I found the very simple reason for the above code not to work: The @PostActivate and @PrePassivate is only being run for Stateful Session Beans. Changing them to @PostConstruct and @PreDestroy everything works!