使用JNDI数据源的Spring数据jpa存储库集成测试

时间:2015-12-13 08:48:33

标签: spring jpa junit jndi

我们正在为Spring数据JPA存储库数据源使用JNDI数据源。 在编写集成测试时,尝试创建JNDI数据源,如下所示。 但仍然是

SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
DriverAdapterCPDS cpds = new DriverAdapterCPDS();
cpds.setDriver("com.mysql.jdbc.Driver");
cpds.setUrl("jdbc:mysql://localhost:3306/test?autoReconnect=true");
cpds.setUser("");
cpds.setPassword("");

SharedPoolDataSource dataSource = new SharedPoolDataSource();
dataSource.setConnectionPoolDataSource(cpds);
dataSource.setMaxActive(10);
dataSource.setMaxWait(50);
builder.bind("jdbc/testDB", dataSource);
builder.activate();

运行maven JUnit Tests时获取以下异常

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!

0 个答案:

没有答案