首页 > 编程语言 > 详细

spring学习笔记

时间:2019-01-27 22:47:44      阅读:177      评论:0      收藏:0      [点我收藏+]

一:spring入门

1:新建java project,在项目名字下面建立lib,

技术分享图片

2:在applicationContext.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.xsd">
  <bean id="SpringHello" class="com.wth.cn.SpringHello">(注意此处为类全名,是通过控制反转的方式创建对象的,所以必须在该类(SpringHello)中要有无参构造方法)

    <property name="name2" value="小猫"></property>
  </bean>
</beans>

3:在Main类中写

public static void main(String[] args){
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
SpringHello springHello = (SpringHello)ctx.getBean("SpringHello");
System.out.println(springHello.getName2());
// SpringHello springHello=new SpringHello();
// springHello.setName("小狗");
// System.out.println(springHello.getName());
}

二:IOC

1:IOC容器作用

技术分享图片

技术分享图片

 技术分享图片

技术分享图片

spring学习笔记

原文:https://www.cnblogs.com/wth21-1314/p/10327876.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!