My datasource-config.xml just contains one line for scanning for spring-data-jpa repositories...
<jpa:repositories base-package="net.findme.server.repository"></jpa:repositories>
And it's in src/main/resources..:\
Printable View
My datasource-config.xml just contains one line for scanning for spring-data-jpa repositories...
<jpa:repositories base-package="net.findme.server.repository"></jpa:repositories>
And it's in src/main/resources..:\
Well something you are doing in is trying to use a web bean as Marten stated. If its not in the configuration its somethinng you are doing in your test case. Can you provide a small sample application so I can reproduce this? I am doing exactly what it sounds like you are trying to do in mulitiple projects for my integration testing and I don't have this issue.
Thanks,
This is my testcase, that causes the exception above...
Here's an excerpt of my project folder, if you want to have a look...Code:@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader=AnnotationConfigContextLoader.class, classes = {DataSourceConfig.class})
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
@Transactional
public class RoleRepositoryTest {
/**
* EntityManager for verifying the results of data manip1ulation by the {@code RoleRepository} interface
*/
@PersistenceContext
private EntityManager _entityManager;
@Inject
private RoleRepository _repository;
@Inject
private RoleGenerator _roleGenerator;
@Test
public void testSaveRole() {
final Role role = _roleGenerator.getRole();
assertNull(role.getPrimaryKey());
assertNull(role.getRoleId());
assertFalse(role.primaryKeyExists());
final Role saved = _repository.save(role);
assertTrue(role.getPrimaryKey() != null);
assertTrue(saved.getPrimaryKey() != null);
assertTrue(role.getPrimaryKey() == saved.getPrimaryKey());
final long id = role.getPrimaryKey();
final TypedQuery<Role> query = _entityManager.createQuery("from Role r where r.roleId = ?1", Role.class);
query.setParameter(1, role.getPrimaryKey());
final Role result = query.getSingleResult();
assertEquals(result, role);
assertEquals(result.getRoleName(), role.getRoleName());
}
Thanks!
I did not have your database set up and I did not have a chance to use an embedded one to mock it out but on first glance I can see you have
@ComponentScan(basePackages = { "net.findme.server" }) on your dbconfig. Remove that line. You already have it in one of your other configs so its not needed and when you pull it in on your test case you are bringing in the web beans.
Alternatively if you really want that in that config file create a DbTestConfig.java in your /src/test/java/ that looks like theh one you have but does not have that line. And bring in that config file on your test case. Either way I think that will solve your issue.
Thanks,
Hi guys,
The following are open JIRA issues related to this topic. Feel free to watch them.
- ApplicationContext fails to load in tests using Java-based config and WebMvcConfigurationSupport
- Add support for loading a WebApplicationContext with the TestContext Framework
Regards,
Sam
FYI:
This issue has been resolved.
Specifically, as of Spring 3.2 RC1, you can annotate your test class with @WebAppConfiguration to instruct the Spring TestContext Framework to load a WebApplicationContext for your tests. This in turn ensures that a mock ServletContext is available, etc.
See SPR-5243 for further details.
Regards,
Sam
markuse1501,
As an aside, you can simplify your test configuration as follows:
Note the omission of unnecessary default overrides.Code:@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DataSourceConfig.class)
@Transactional
public class RoleRepositoryTest { /* ... */ }
- Sam