Hi I have a controller that I am trying to test, without mocking.
@Controller
public class MyController
{
@Autowired
private Type1 service1;
@Autowired
private Type2 service2;
....
}
Test Class:
public class testController
{
@Autowired
private MyController controller;
@Before
public void setUp()
{
//setupStuff
}
@Test
public void testControllerMethod()
{
//Test method
}
}
When debugging through the test, I get the value for controller but the value for autowired service1 and 2 are null.
The xml file does have base packages for all the services and controller in <context: component-scan>
Which if removed gives me error creating bean. Even if i remove one of the service base packages.
Is there anything test specific I need to add to my configuration?
Type1:
public interface Type1
{
String method1();
String method2();
}
Type1 implementing class that is autowired is:
@Service
public class Type1Class implements Type1
{
@Autowired
private Type3 service3;
//Methods implementatoin of Type1
}
Type2 is similar to this.
@Autowired
, beans need to be declared or scanned for. – Sotirios Delimanolis 2 days agoType1
andType2
. – GriffeyDog 2 days agoType1
andType2
with@Service
? – GriffeyDog 2 days ago