I am trying to configure Spring, Junit and Hibernate (to enable @Autowire
annotation for our test cases). My current setup is this:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({
"file:src/main/webapp/WEB-INF/applicationContext.xml",
"file:src/main/webapp/WEB-INF/dispatcher-servlet.xml",
})
public class UserManagementServiceTest {...}
However, the initialization fails with
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
We've defined various credentials in context.xml
files which are picked up by tomcat when running the application. The structure is as below
<Context>
<Resource name="abc/abcManager"
auth="Container"
type="path.to.file"
factory="org.apache.naming.factory.BeanFactory"
attr1="asas"
attr2="asda"/>
</Context>
These attributes are then picked up using InitialContext
class.
How do I configure the above functionality for our test cases?
Adding the context.xml
file to ContextConfiguration
gives the error
java.lang.IllegalStateException: Failed to load ApplicationContext
...
Caused by: org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 10; cvc-elt.1: Cannot find the declaration of element 'Context'.