Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring aspectj jar not configured correctly

I am getting this error when I tried to use a JPA object created by Roo.

Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)

I have followed some online advice to add the spring-aspects.jar to aspectj path in Eclipse but I still get this error. Does anyone know how to solve this?

The environment I am using is Spring 3.0.5, Hibernate 3.6 and JBoss 6.0.0.Final.

like image 460
newguy Avatar asked Jan 14 '11 06:01

newguy


3 Answers

Go to STS ROO console (right click in the project in STS, then Spring Tools, then Open Spring Roo) Type in the prompt perform clean (will perform Maven clean) Then type perform eclipse

It should work!

like image 151
Michel Bilodeau Avatar answered Oct 19 '22 21:10

Michel Bilodeau


Looks like you haven't injected Entity Manager.

Webapps (possible causes):

  • You didn't add entity manager factory to your applicationContext.xml

Java Applications:

  • You didn't add entity manager factory to your applicationContext.xml
  • Wrong application initialization (see below)

    public class SampleApp {
        public static void main(String[] args) {
            SampleApp obj = new SampleApp();
    
            // Injecting dependencies into application
            ConfigurableApplicationContext applicationContext = 
                    new ClassPathXmlApplicationContext("<PATH-TO>/applicationContext.xml");
            applicationContext.registerShutdownHook();
            applicationContext.getBeanFactory().autowireBeanProperties(
                    obj, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    
            // Do the work
        }
    }
    
like image 26
João Melo Avatar answered Oct 19 '22 19:10

João Melo


I had this problem too, and found the answer here: http://whyjava.wordpress.com/2012/02/13/fixing-exception-entity-manager-has-not-been-injected-is-the-spring-aspects-jar-configured-as-an-ajcajdt-aspects-library/

In my case, I needed to create a file called <classname>_Roo_Configurable.aj with the following content:

privileged aspect <classname>_Roo_Configurable { declare @type: <classname>: @Configurable; }

This explained why existing classes worked but new ones that I had created did not. The _Configurable.aj file did not (and still does not) show up in the package explorer in STS.

(I know this answer is incredibly late but I hope it helps someone else!)

like image 34
pete the pagan-gerbil Avatar answered Oct 19 '22 20:10

pete the pagan-gerbil