IDEA的spring入门程序

创建新项目IDEA的spring入门程序

记得打勾IDEA的spring入门程序

CTRL+ALT+SHIFT+S打开添加外部jar包spring-framework,文末提供链接IDEA的spring入门程序

做完添加确保有以上5个包IDEA的spring入门程序

测试程序

public interface UserService {
    public void say();
}
public class UseServiceImpl implements UserService {

    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public void say() {
        this.userDao.say();
        System.out.println("say goodbye");
    }

}

xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
    <bean id="userDao" class="com.demo.ioc.UserDaoImpl"/>
    <bean id="userService" class="com.demo.ioc.UseServiceImpl">
            <property name="userDao" ref="userDao"/>
                    </bean>
</beans>

运行

    public static void main(String[] args) {
        ApplicationContext applicationContext=
                new ClassPathXmlApplicationContext("beans.xml");
        UserService userService;
        userService = (UserService) applicationContext.getBean("userService");
        userService.say();
    }
}

实现IDEA的spring入门程序

链接:https://pan.baidu.com/s/1fDPM5KgYF2i0YG2k7crQ-A
提取码:ah84

上一篇:Spring学习1_IOC理论推导


下一篇:2.9(基于XML的两种装配实例化对象的方式)、(基于annotation的装配方式)、(自动装配)