junit4 - JUnit + Spring Integration + java.lang.IllegalStateException: Failed to load ApplicationContext -
i facing issue junit while running unit test cases.i using spring 4.3.2.release , junit 4.12 , maven 3.3.9. i'm not sure why i'm getting exception while running test code.i tried possible ways execute code got failed run test cases.
exception is:
java.lang.illegalstateexception: failed load applicationcontext @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:308) @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.injectdependencies(dependencyinjectiontestexecutionlistener.java:109) @ org.springframework.test.context.support.dependencyinjectiontestexecutionlistener.preparetestinstance(dependencyinjectiontestexecutionlistener.java:75) @ org.springframework.test.context.testcontextmanager.preparetestinstance(testcontextmanager.java:333) @ org.springframework.test.context.junit4.springjunit4classrunner.createtest(springjunit4classrunner.java:220) @ org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall(springjunit4classrunner.java:301) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15) @ org.springframework.test.context.junit4.springjunit4classrunner.methodblock(springjunit4classrunner.java:303) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:240) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:49) @ org.junit.runners.parentrunner$3.run(parentrunner.java:193) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:52) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:191) @ org.junit.runners.parentrunner.access$000(parentrunner.java:42) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:184) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:70) @ org.junit.runners.parentrunner.run(parentrunner.java:236) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:180) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:86) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:459) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:678) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:382) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:192)
caused by: org.springframework.beans.factory.beandefinitionstoreexception: ioexception parsing xml document class path resource [spring-beans/applicationcontext-b2b-transport1.xml]; nested exception java.io.filenotfoundexception: class path resource [spring-beans/applicationcontext-b2b-transport1.xml] cannot opened because not exist @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:341) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:302) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:143) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:178) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:149) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:212) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:81) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:1) @ org.springframework.test.context.testcontext.loadapplicationcontext(testcontext.java:280) @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:304) ... 24 more caused by: java.io.filenotfoundexception: class path resource [spring-beans/applicationcontext-b2b-transport1.xml] cannot opened because not exist @ org.springframework.core.io.classpathresource.getinputstream(classpathresource.java:158) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:328) ... 33 more
pom.xml
<?xml version="1.0" encoding="utf-8"?> <project xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"> <modelversion>4.0.0</modelversion> <groupid>com.bt.b2b.gateway</groupid> <artifactid>b2babc</artifactid> <packaging>pom</packaging> <version>1.0-snapshot</version> <name>b2babc_ws</name> <url>http://maven.apache.org</url> <!-- shared version number properties --> <properties> <!--env>dev</env --> <!-- <org.springframework.version>4.1.8.release</org.springframework.version> commented spring library updates--> <org.springframework.version>4.3.2.release</org.springframework.version> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <timestamp>${maven.build.timestamp}</timestamp> <maven.build.timestamp.format>yyyy-mm-dd-hh-mm</maven.build.timestamp.format> </properties> <build> <plugins> <plugin> <artifactid>maven-antrun-plugin</artifactid> <!-- <version>1.3</version> commented spring library updates --> <version>1.8</version> </plugin> <plugin> <artifactid>maven-clean-plugin</artifactid> <!-- <version>2.4.1</version>commented spring library updates --> <version>3.0.0</version> <executions> <execution> <id>auto-clean</id> <phase>initialize</phase> <goals> <goal>clean</goal> </goals> </execution> </executions> </plugin> </plugins> <!--filters> <filter>${env.m2_home}/conf/${env}.properties</filter> </filters--> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <testresources> <testresource> <directory>src/test/resources</directory> <filtering>true</filtering> </testresource> </testresources> <!-- <finalname>openreachssgatewayear-${maven.build.timestamp}</finalname> --> </build> <dependencies> <!-- open source dependencies --> <dependency> <groupid>emw-logging-framework</groupid> <artifactid>logging</artifactid> <version>3_3_12_2</version> <scope>provided</scope> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-core</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-beans</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-aop</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-tx</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-orm</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-oxm</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jms</artifactid> <version>${org.springframework.version}</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-test</artifactid> <version>${org.springframework.version}</version> <scope>test</scope> </dependency> <dependency> <groupid>org.apache.xmlbeans</groupid> <artifactid>xmlbeans-xpath</artifactid> <version>2.4.0</version> <!--<scope>provided</scope>--> </dependency> <dependency> <groupid>net.sf.saxon</groupid> <artifactid>saxon</artifactid> <version>9</version> </dependency> <dependency> <groupid>net.sf.saxon</groupid> <artifactid>saxon9-dom</artifactid> <version>9.1.0.8</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-api</artifactid> <version>1.6.4</version> </dependency> <dependency> <groupid>org.slf4j</groupid> <artifactid>slf4j-log4j12</artifactid> <version>1.6.4</version> </dependency> <dependency> <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>1.2.16</version> </dependency> <!-- b2b specific dependencies --> <dependency> <groupid>actionplan</groupid> <artifactid>actionplan</artifactid> <!-- <version>1.6</version> added storebusiness receipt in action plan 1.7 --> <version>1.7</version> </dependency> <dependency> <groupid>e537deliveryreceipt</groupid> <artifactid>e537deliveryreceipt</artifactid> <version>1.0</version> </dependency> <dependency> <groupid>com.bt</groupid> <artifactid>aliasnamesplan</artifactid> <version>1.0</version> </dependency> <dependency> <groupid>supplieroutboundactionplan</groupid> <artifactid>supplieroutboundactionplan</artifactid> <version>1.0</version> </dependency> <dependency> <groupid>com.bt</groupid> <artifactid>aliasnamesplansinglestagecompr</artifactid> <version>1.0</version> </dependency> <dependency> <groupid>nonamespace</groupid> <artifactid>b2bpropertymappings</artifactid> <version>1.1</version> </dependency> <dependency> <groupid>nonamespace</groupid> <artifactid>b2bbesconfig</artifactid> <version>1.3</version> </dependency> <dependency> <groupid>nonamespace</groupid> <artifactid>b2bmisservices</artifactid> <version>1.1</version> </dependency> <dependency> <groupid>nonamespace</groupid> <artifactid>btacknowledgements</artifactid> <version>1.1</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency> <!-- added these dependencies eassymock testing--> <dependency> <groupid>org.easymock.easymock</groupid> <artifactid>easymock</artifactid> <version>3.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.objectweb.asm</groupid> <artifactid>asm</artifactid> <version>3.0</version> <scope>test</scope> </dependency> <dependency> <groupid>net.sf.cglib</groupid> <artifactid>cglib</artifactid> <version>2.2.2</version> <scope>test</scope> </dependency> <dependency> <groupid>org.objenesis</groupid> <artifactid>objenesis</artifactid> <version>1.2</version> <scope>test</scope> </dependency> <!-- eassymock end --> </dependencies> <modules> <module>components/p</module> <module>components/b2ba</module> <module>components/b2bb</module> <module>components/b2bc</module> <module>components/b2bd</module> <module>components/b2be</module> <module>components/f</module> <module>components/g</module> <module>components/h</module> <module>components/i</module> <module>components/j</module> <module>components/k</module> <module>components/l</module> <module>components/m</module> <module>ears/o</module> <module>components/b2bn</module> </modules> <!-- profiles , matching property filenames --> <profiles> <profile> <id>btr</id> <activation> <activebydefault>true</activebydefault> </activation> <properties> <build.profile.id>btr</build.profile.id> <b2blogpath></b2blogpath> <earname>somexyzear</earname> </properties> <build> <filters> <filter>${env.m2_home}/conf/${build.profile.id}.properties</filter> </filters> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>btorss</id> <activation> <activebydefault>true</activebydefault> </activation> <properties> <build.profile.id>btorss</build.profile.id> <b2blogpath></b2blogpath> <earname>somexyzear</earname> <!-- <timestamp>${maven.build.timestamp}</timestamp> --> <!-- <maven.build.timestamp.format>yyyy-mm-dd hh:mm</maven.build.timestamp.format> --> </properties> <build> <filters> <filter>${env.m2_home}/conf/${build.profile.id}.properties</filter> </filters> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>btws</id> <activation> <activebydefault>false</activebydefault> </activation> <properties> <build.profile.id>btws</build.profile.id> <b2blogpath></b2blogpath> <earname>somexyzear</earname> </properties> <build> <filters> <filter>${env.m2_home}/conf/${build.profile.id}.properties</filter> </filters> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>btgs</id> <activation> <activebydefault>false</activebydefault> </activation> <properties> <build.profile.id>btgs</build.profile.id> <b2blogpath></b2blogpath> <earname>somexyzear</earname> </properties> <build> <finalname>${project.artifactid}-${project.version}-${timestamp}</finalname> <filters> <filter>${env.m2_home}/conf/${build.profile.id}.properties</filter> </filters> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> <profile> <id>btor</id> <activation> <activebydefault>false</activebydefault> </activation> <properties> <build.profile.id>btor</build.profile.id> <b2blogpath></b2blogpath> <earname>openreachgatewayear</earname> </properties> <build> <filters> <filter>${env.m2_home}/conf/${build.profile.id}.properties</filter> </filters> <resources> <resource> <filtering>true</filtering> <directory>src/main/resources</directory> </resource> </resources> </build> </profile> </profiles> </project>
below code junit testcase
package com.java.autowire; import org.junit.test; import org.junit.runner.runwith; import org.springframework.beans.factory.annotation.autowired; import org.springframework.test.context.contextconfiguration; import org.springframework.test.context.junit4.springjunit4classrunner; @contextconfiguration(locations = {"classpath:spring-beans/applicationcontext-b2b-transport1.xml"}) @runwith(springjunit4classrunner.class) public class testmainapp { /*@autowired private student student;*/ @test public void getname(){ //do here..... } }
below code studenet.java
package com.java.autowire; import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.required; public class student { private integer age; private string name; public string getname() { return name; } //@autowired public void setname(string name) { this.name = name; } public integer getage() { return age; } //@autowired(required=false) public void setage(integer age) { this.age = age; } }
below configuration file named bean.xml
<?xml version="1.0" encoding="utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context = "http://www.springframework.org/schema/context" xsi:schemalocation="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"> <context:annotation-config/> <!-- definition student bean --> <bean id = "student" class = "com.java.autowire.student"> </bean> </beans>
hint: configuration file under src/main/resource/spring-beans/applicationcontext-b2b-transport1.xml
tried possible ways. please me out issue.
the error seems pretty obvious...
class path resource [spring-beans/applicationcontext-b2b-transport1.xml] cannot opened because not exist
...where referencing file?
you loading...
@contextconfiguration(locations = {"classpath:sree/bean.xml"})
not /spring-beans/beans.xml
.
Comments
Post a Comment