Spring-boot how to use autowired class properties in called method -
i have following class in spring-boot application
public class classa { @autowired propertiesclass propertiesclass; public integer getmesomevalue(integer someparameter) { // uses methods of propertiesclass } }
here, propertiesclass contains methods reads property values application.properties file. want unit test getmesomevalue method. unit test class given below
@runwith(springjunit4classrunner.class) @springapplicationconfiguration(myapplication.class) @webintegrationtest public class classatest { @test public void testgetmesomevalue() { classa classa = new classa(); assert.assertsame("received expected response", classa.getmesomevalue(6025), 2345); } }
when run unit test, null pointer exception @ point methods of propertiesclass invoked inside getmesomevalue method. there way in spring-boot make @autowired work?
instead of
classa classa = new classa();
do this...
@autowired classa classa;
so classa bean available within spring container.
Comments
Post a Comment