Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use JUnit tests with Spring Roo? (Problems with EntityManager)
    primarykey
    data
    text
    <p>I'm trying to write a JUnit test for a Spring Roo project. If my test requires use of the entity classes, I get the following Exception:</p> <pre><code>java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?) </code></pre> <p>The Spring Aspects JAR looks to be configured correctly. In particular, I have the following in the <code>pom.xml</code> file:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.springframework&lt;/groupId&gt; &lt;artifactId&gt;spring-aspects&lt;/artifactId&gt; &lt;version&gt;${spring.version}&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>and </p> <pre><code>&lt;plugin&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> <p>and the classes that use the entity classes work fine, when not called from a JUnit test. Any idea how I can set things up so that the Entity manager is injected from a JUnit test?</p> <p>Here is my Test class (more or less):</p> <pre><code>public class ServiceExampleTest { @Test public void testFoo() { FooService fs = new FooServiceImpl(); Set&lt;Foo&gt; foos = fs.getFoos(); } } </code></pre> <p>This is enough to throw the exception. The FooServiceImpl class returns a Set of Foo, where Foo is an entity class. The <code>getFoos()</code> method works when the application is run in the usual way. The problem only comes in the context of unit tests.</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