. @Stateless , @Local, , , bean, @EJB . , , Websphere Liberty Profile, - beans.xml WEB-INF, NPE cdi bean.
@Stateless
public class ServiceImpl implements Service {
public void doSomething() {
System.out.println("I did something");
}
@PostConstruct
public void postConstruct() {
System.out.println("I was just constructed");
}
@PreDestroy
public void preDestroy() {
System.out.println("Arrgg I am being destroyed");
}
}
@Local
public interface Service {
public void doSomething();
}
public class Client {
@EBJ Service service;
public void someMethod() {
service.doSomething();
}
}
../WEB-INF/beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>
post bean, , , .