1.1、 applicationContext.xml
配置文件
1.2 、@Component
注入bean,XML中可以不用再继续配置bean
package com.chris.pojo;
import org.springframework.stereotype.Component;
1.3 、衍生注解
1.31、@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;
1.32、注解注入
1.33、调用方式
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);
}
}