spring

作者: 非非非非常胖的大公鸡9527 | 来源:发表于2018-08-10 11:13 被阅读0次

http://www.cnblogs.com/DebugLZQ/archive/2013/06/05/3107957.html

https://www.cnblogs.com/xxzhuang/p/5948902.html

http://wiki.jikexueyuan.com/project/spring/overview.html

Spring

https://blog.csdn.net/qq_32390853/article/details/78078847

image.png

Spring的两个核心功能:

1.IOC--控制反转:就是将bean初始化加载到容器中,加载的方式有:1.Spring注解方式(相对更好) 2.Spring XML配置方式

2.AOP--面向切面编程

问题:spring怎么知道应该哪些Java类当初bean类处理?

答案:使用配置文件或者注解的方式进行标识需要处理的java类!

注解:

@Component :标准一个普通的spring Bean类。
@Repository:标注一个DAO组件类。
@Service:标注一个业务逻辑组件类。
@Controller:标注一个控制器组件类。

传统的程序实现:

调用printMessage方法,分为3步:

1. new一个HelloSpring的实例对象
2. 设置实例的message属性
3. 调用对象的printMessage()方法

//HelloSpring helloSpring = new HelloSpring();
//helloSpring.setMessage("guhao");
//helloSpring.printMessage();

spring的实现:

1. 创建一个Spring的IOC容器对象 2. 从IOC容器中获取Bean实例 3. 调用printMessage()方法

ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml"); HelloSpring helloSpring = (HelloSpring) context.getBean("helloSpring"); helloSpring.printMessage();

执行到第一步创建IOC容器对象的时候就调用了HelloSpring类的构造方法和set方法

?同时需要配置或者注解???

<bean id = "helloSpring" class="HelloSpring">
<property name = "message" value = "guhao"> </property>
</bean>

相关文章

网友评论

      本文标题:spring

      本文链接:https://www.haomeiwen.com/subject/csdkbftx.html