How do you inject EJBs in Struts 2 actions? Are you using CDI? Are you using the Struts2 CDI plugin?
Update: The problem is that the container is not creating the Struts objects, Struts is, so the container doesn't get the opportunity to inject anything. You'll have to use the mentioned plugin for CDI to enable injection in your actions.
If you want to give it a try, get Struts 2 sources:
svn co http://svn.apache.org/repos/asf/struts/struts2/trunk/ struts2
Then cd
into the struts2
directory and run the following command (this will compile the required modules for the struts-cdi-plugin
)
mvn install -pl plugins -am
Then get the sources of the cdi-plugin:
svn co https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-plugin/
And compile it:
mvn install
Now, with the following dependencies in my pom.xml:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-cdi-plugin</artifactId>
<version>2.2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.8.0.GA</version>
</dependency>
I was able to get an EJB injected in an Action:
public class HelloWorld extends ActionSupport {
@Inject
HelloEJB helloEjb;
@Override
public String execute() throws Exception {
setMessage(helloEjb.getMessage());
return SUCCESS;
}
private String message;
public void setMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
See https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-example/ for an example.