Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How do you inject EJBs in Struts 2 actions? Are you using CDI? Are you using the <a href="http://www.mailinglistarchive.com/html/dev@struts.apache.org/2009-12/msg00024.html" rel="nofollow noreferrer">Struts2 CDI plugin</a>?</p> <p><strong>Update:</strong> 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 <a href="http://www.mailinglistarchive.com/html/dev@struts.apache.org/2009-12/msg00024.html" rel="nofollow noreferrer">plugin for CDI</a> to enable injection in your actions.</p> <p>If you want to give it a try, get Struts 2 sources:</p> <pre><code>svn co http://svn.apache.org/repos/asf/struts/struts2/trunk/ struts2 </code></pre> <p>Then <code>cd</code> into the <code>struts2</code> directory and run the following command (this will compile the required modules for the <code>struts-cdi-plugin</code>)</p> <pre><code>mvn install -pl plugins -am </code></pre> <p>Then get the sources of the cdi-plugin:</p> <pre><code>svn co https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-plugin/ </code></pre> <p>And compile it:</p> <pre><code>mvn install </code></pre> <p>Now, with the following dependencies in my pom.xml:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.apache.struts&lt;/groupId&gt; &lt;artifactId&gt;struts2-core&lt;/artifactId&gt; &lt;version&gt;2.2.0-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.struts&lt;/groupId&gt; &lt;artifactId&gt;struts2-cdi-plugin&lt;/artifactId&gt; &lt;version&gt;2.2.0-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;javassist&lt;/groupId&gt; &lt;artifactId&gt;javassist&lt;/artifactId&gt; &lt;version&gt;3.8.0.GA&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>I was able to get an EJB injected in an Action:</p> <pre><code>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; } } </code></pre> <p>See <a href="https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-example/" rel="nofollow noreferrer">https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-cdi-example/</a> for an example.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload