public class TestUser {
@Autowired
private User user;
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
new TestUser().user.sayHello("LeaX");
}
}
这样是不对的,应该是下面这样<pre name="code" class="java">@Service
public class TestUser {
@Autowired
private User user;
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
TestUser t = (TestUser) ctx.getBean("testUser");
t.user.sayHello("LeaX");
}
}