java - Bean autowire fail when running tests only -



java - Bean autowire fail when running tests only -

hopefully might have reply problem. have autowire problem occuring when run tests not else. exception pretty clear says 'myfield' missing. field inherited base of operations class. cannot find reply problem anywhere seek luck here.

the exception org.springframework.beans.factory.beancreationexception: error creating bean name 'myservice': injection of autowired dependencies failed; nested exception java.lang.nosuchfielderror: myfield my base of operations class public abstract class commonstuff { protected string myfield; // 1 thats gone missing public abstract void setmyfield(string myfield); } my service @service("myservice") public class myservice extends commonstuff { @value("${myproperty.myfield}") public void setmyfield(string myfield) { this.myfield = myfield; } ... } my controller @controller public class mycontroller { @autowired private myservice myservice; public void setmyservice(myservice myservice) { this.myservice = myservice; } ... } my application-context.xml

nothing seems left out.

<context:component-scan base-package="com.myapp" /> <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer"> <property name="systempropertiesmodename" value="system_properties_mode_override" /> <property name="ignoreresourcenotfound" value="true" /> <property name="locations"> <list> <value>classpath:my.properties</value> <value>classpath:myother.properties</value> </list> </property> </bean> my.properties myproperty.myfield=some value my test @runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "classpath:application-context.xml" }) public class mycontrollertest { @autowired mycontroller mycontroller; @mock myservice myservice; @test public void myservicetest() { // stuff myservice } ... } the problem

as mentioned code runs fine spring has problem autowiring whenever seek run test.

the problem not test wiring when starting test. somehow spring cannot find myfield abstract commonstuff class says myservice not have field.

if needed can post total stacktrace think essense of exception here.

i gave , moved myfield service , skipped setmyfield. how now.

base class public abstract class commonstuff { public abstract string getmyfield(); public void docommonstuff() { // utilize getmyfield() } } my service @service("myservice") public class myservice extends commonstuff { @value("${myproperty.myfield}") private string myfield; @override public string getmyfield() { homecoming myfield; } ... }

this solves wanted since have access myfield commonstuff.

java spring inheritance junit autowired

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

java - Parsing XML, skip certain tags -

c# - ASP.NET MVC Sequence contains no matching element -