配置文件
注入bean,XML中可以不用再继续配置bean
package com.chris.pojo;
?
import org.springframework.stereotype.Component;
?
@Repository(Dao层)、 @Service(Service层)、 @Controller(层)
package com.chris.dao;
?
import org.springframework.stereotype.Repository;
?
package com.chris.Services;
?
import org.springframework.stereotype.Service;
?
package com.chris.Controller;
?
import org.springframework.stereotype.Controller;
?
调用方式
import com.chris.dao.UserDao;
import com.chris.pojo.UserPOJO;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
?
public class MyTest {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applictionContext.xml");
UserPOJO userPOJO = (UserPOJO) context.getBean("userPOJO");
System.out.println(userPOJO.Name);
?
}
}
原文:https://www.cnblogs.com/wooroc/p/13440792.html