Note that there are some explanatory texts on larger screens.

plurals
  1. POCompile Time Weaving Null Pointer Exception
    primarykey
    data
    text
    <h1>Edit 7:</h1> <p>The problem seems to be how to get <code>@Configurable</code> working with <code>HttpSessionListener</code>, a workaround is suggested, but I'dd prefer not to to interact with the <code>WebApplicationContext</code> directly:</p> <pre><code> @Configurable(autowire = Autowire.BY_TYPE, preConstruction = true) public class SessionListener implements HttpSessionListener { private static final Logger log; @Autowired private A a; @Override public void sessionCreated(HttpSessionEvent se) { a.doSomething(); // &lt;- Throws NPE log.info("New session was created"); } @Override public void sessionDestroyed(HttpSessionEvent se) { log.info("A session was closed"); } } </code></pre> <h1>Edit 6:</h1> <p>I made the sample project simpler: you can now run it from CLI</p> <ol> <li>download and extract project: <a href="http://www.2shared.com/file/KpS5xeqf/dynatable.html" rel="nofollow">http://www.2shared.com/file/KpS5xeqf/dynatable.html</a></li> <li>run mvn clean aspectj:compile</li> <li>run mvn gwt:run</li> <li>You should see in your CLI that "Why is consumer NULL here?" is printed. </li> <li>Expected instead is:cunsumer is not NULL!</li> </ol> <p>The end is near :D</p> <h1>Edit 5: Sample project in GWT: pls run this in GWT development mode</h1> <p><a href="http://www.2shared.com/file/eai0PV-5/dynatable.html" rel="nofollow">http://www.2shared.com/file/eai0PV-5/dynatable.html</a></p> <p>You will get a NPE at sessionCreated()</p> <p>Requirements to run are maven + gwt 2.5</p> <h1>Edit 4:</h1> <p>It seemed the sample project wasn't a very representative one. I should reformulate the problem:</p> <p>In eclipse I use GWT Development mode when I run the project as a web application. In some way this doesn't call the aspectj compiler. At least that's the only reason I can think of.</p> <p><strong>Question: How to setup Compile Time Weaving to work with running as web application (GWT Development mode).?</strong></p> <h1>Edit 3:</h1> <p>I made a small sample project in <strong>Eclipse 4.2.1, M2e 1.4.0, STS 3.1.0, AJDT 2.2.2</strong> that demonstrates the problem: <strong><a href="http://www.2shared.com/file/WZ1T9l9-/autowired.html" rel="nofollow">http://www.2shared.com/file/WZ1T9l9-/autowired.html</a></strong></p> <h1>Edit 2:</h1> <p>As suggested by other similar topics I took the plugins of a standard generated <code>Roo</code> project to avoid conflicting versions. No success yet. (Updated the org.codehaus.mojo above)</p> <h1>Edit 1:</h1> <p>I'm not sure this is normal, but when I start up the web application, I get a long log of what spring is doing , <strong>but nothing mentions any weaving / anything related to Aspectj</strong>...</p> <p>I think the problem is related to this plugin in pom.xml not being compiled as <strong>I don't get any feedback in my console</strong>(I tried many other similar plugins but none work) It seems the plugin is never called when I run the web application:</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;aspectj-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.2&lt;/version&gt; &lt;!-- NB: do not use 1.3 or 1.3.x due to MASPECTJ-90 and do not use 1.4 due to declare parents issue --&gt; &lt;dependencies&gt; &lt;!-- NB: You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --&gt; &lt;dependency&gt; &lt;groupId&gt;org.aspectj&lt;/groupId&gt; &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt; &lt;version&gt;1.7.0&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.aspectj&lt;/groupId&gt; &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt; &lt;version&gt;1.7.0&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;executions&gt; &lt;execution&gt; &lt;goals&gt; &lt;goal&gt;compile&lt;/goal&gt; &lt;goal&gt;test-compile&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;configuration&gt; &lt;outxml&gt;true&lt;/outxml&gt; &lt;aspectLibraries&gt; &lt;aspectLibrary&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt; &lt;/aspectLibrary&gt; &lt;/aspectLibraries&gt; &lt;source&gt;1.6&lt;/source&gt; &lt;target&gt;1.6&lt;/target&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <h1>Original Post:</h1> <p>I've been searching stackoverflow and many other resources, but none of their standard solutions help me to find why an <code>@autowired</code> field yields to <code>Null Pointer Exception (NPE)</code> when accessed.</p> <pre><code>@Configurable(autowire = Autowire.BY_TYPE, preConstruction = true) public class SessionListener implements HttpSessionListener { private static final Logger log; @Autowired private A a; @Override public void sessionCreated(HttpSessionEvent se) { a.doSomething(); // &lt;- Throws NPE log.info("New session was created"); } @Override public void sessionDestroyed(HttpSessionEvent se) { log.info("A session was closed"); } } </code></pre> <p>The A class is declared as follows:</p> <pre><code>@Service public class B implements A { // some implementation } </code></pre> <p>my application context has the relevant parts:</p> <pre><code>&lt;context:spring-configured /&gt; &lt;context:annotation-config /&gt; &lt;context:component-scan base-package='some.package' /&gt; </code></pre> <p>All necessary libraries are there. I use Spring 3.0.2. Due to my environment, I'm only able to use compile time weaving. I'm also using the Google Plugin to start GWT Development Mode. I'm using <code>ADJT</code>, the <code>Spring Tool Suite</code>, <code>m2Eclipse</code> and <code>Google Plugin</code>. I also installed AJDT configurator for m2e v1.0.</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.
 

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