添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
No [ManagedType] was found for the key class.. JPA, H2, EclipseLink, Java Config (no xml) [ message #1453606 ] Mon, 27 October 2014 07:33 Go to next message Hi All,
I am using JPA, H2, EclipseLink, Java Config (no xml). My problem is that I am getting this No [ManagedType] was found for the key class error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.foo.data.repository.RepositoryTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.foo.data.repository.UserRepository com.foo.data.repository.RepositoryTest.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No [ManagedType] was found for the key class [com.foo.data.model.User] in the Metamodel - please verify that the [Managed] class was referenced in persistence.xml using a specific <class>com.foo.data.model.User</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:376) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Here is an excerpt from my @Configuration class.
package com.foo.config; import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; import javax.sql.DataSource; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.eclipse.persistence.jpa.PersistenceProvider; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.instrument.classloading.SimpleLoadTimeWeaver; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.Database; import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect; import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import com.foo.webdriver.WebDriverFactory.Browser; * Class contains configuration details for Selenium tests. * @author robbram @ComponentScan( basePackages = { "com.foo.*"}, excludeFilters = @Filter(type = FilterType.ANNOTATION, value = Configuration.class)) @Configuration @EnableJpaRepositories(basePackages = "com.foo.data.repository") public class SeleniumAppTestConfig implements InitializingBean { @Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); return builder.setType(EmbeddedDatabaseType.H2) .addScript("SeleniumCreateScript.sql").build(); @Bean public Properties jpaProperties() { Properties props = new Properties(); props.setProperty("eclipselink.ddl-generation", "create-tables"); props.setProperty("eclipselink.weaving", "false"); props.setProperty("eclipselink.logging.level", "FINEST"); props.setProperty("eclipselink.logging.parameters", "true"); return props; @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final PersistenceProvider persistenceProvider = new PersistenceProvider(); final EclipseLinkJpaVendorAdapter vendorAdapter = new EclipseLinkJpaVendorAdapter(); vendorAdapter.setGenerateDdl(true); vendorAdapter.setShowSql(true); vendorAdapter.setDatabase(Database.H2); LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setDataSource(dataSource()); emf.setPackagesToScan("com.foo.data.model"); emf.setLoadTimeWeaver(new SimpleLoadTimeWeaver()); emf.setPersistenceProvider(persistenceProvider); emf.setPersistenceUnitName("SeleniumTests"); emf.setJpaVendorAdapter(vendorAdapter); emf.setJpaProperties(jpaProperties()); emf.afterPropertiesSet(); return emf; @Bean public PlatformTransactionManager transactionManager(){ JpaTransactionManager transactionManager = new JpaTransactionManager(); transactionManager.setEntityManagerFactory( entityManagerFactory().getObject() ); return transactionManager; @Bean public EclipseLinkJpaDialect exceptionTranslator() { return new EclipseLinkJpaDialect(); Here is my Entity class (in the com.foo.data.model package):
@Entity @Table(name = "USER", schema = "SELENIUM") public class User { @Column (name = "USERNAME") private String username; @Column (name = "PASSWORD") private String password; public String getUsername() { return username; public void setUsername(String username) { this.username = username; public String getPassword() { return password; public void setPassword(String password) { this.password = password; @Override public String toString() { return String.format( "User[username=%s, password='%s']", username, password); Here is my Repository:
@Repository public interface UserRepository extends CrudRepository <User, String> { List<User> findByLastUsername(String username); And finally, here is my Test:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = SeleniumAppTestConfig.class) public class RepositoryTest { /** Logger for this class. */ private static final Logger LOG = Logger.getLogger(RepositoryTest.class); @Autowired private UserRepository userRepository; @Test public void testThings() { final Iterable<User> users = userRepository.findAll(); for (User user: users) { LOG.info("user [" + user + "]."); Any assistance would be most appreciated!
Re: No [ManagedType] was found for the key class.. JPA, H2, EclipseLink, Java Config (no xml) [ message #1454305 is a reply to message #1453606 ] Tue, 28 October 2014 08:10 Go to previous message Previous Topic: Problem with ReadAllQuery and hierarchical data Next Topic: Many to many with extra data in join table Goto Forum:

Current Time: Mon Jul 01 17:44:20 GMT 2024

Powered by FUDForum . Page generated in 0.03725 seconds