Hi,
I know this is quite an old thread but I've got a similar problem:
Exception ist the same "Entitymanager has not been injected" - happening also when running the spring roo generated tests.
Now I've tried to initialize the context in my startup class of wicket. The result is that nothing has changed, the exception is still there. What I'm wondering about ist when I add the EntityManager to my startup class the entitymanager gets injected successfully.
Code:
package de.bens.releaseviewer.web;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import de.bens.releaseviewer.web.page.HomePage;
@Component
public class ReleaseViewerApplication extends WebApplication {
@Autowired
private ApplicationContext context;
// @PersistenceContext // This is working!
// private EntityManager em;
public ReleaseViewerApplication() {
}
private static final String DEFAULT_ENCODING = "UTF-8";
@Override
protected void init() {
super.init();
getComponentInstantiationListeners().add(new SpringComponentInjector(this, context, true));
getMarkupSettings().setDefaultMarkupEncoding(DEFAULT_ENCODING);
getRequestCycleSettings().setResponseRequestEncoding(DEFAULT_ENCODING);
}
@Override
public Class<HomePage> getHomePage() {
return HomePage.class;
}
public static WebApplication get() {
return WebApplication.get();
}
}
I already checked that the applicationContext is included in the classpath and whether it's correctly spelled...
This is my applicationContext:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>
<context:spring-configured/>
<context:component-scan base-package="de.bens.releaseviewer">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${database.driverClassName}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
Does anyone have an idea what do I do wrong?
Thanks.
Erik