怎么设置autowired
first u should set up your file structure like below
–fundamental class(+@Component)
–configure (+@ComponentScan)
–Main、Test(+@ContextConfiguration(classes=xxxConfigure.class))if u want to test whether the file is injected…(by Junit4 etc)
here is some emphasis:
First import junit4 api
In the main class,should add the prefix to run the junit4
@Runwith(SpringJUnit4ClassRunner.class)
@Context
@Autowired
public xx xxx;
@Test
public void testMethod(){}
{% endcodeblock %}
current spring doesn't recommend field injection
change like this