首页 > 编程语言 > 详细

Spring_IOC_Xml配置

时间:2021-06-16 10:34:22      阅读:22      评论:0      收藏:0      [点我收藏+]

对象是由Spring容器创建和装配的

Spring通过Xml配置bean(相当于之前的    类 对象名 = new 类)

<?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
https://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="helloSpring" class="com.cyy.Pojo.HelloSpring">
<property name="str" value="HelloSpring"/>
</bean>
<--
  ref引用Spring中创建好的对象
  value是直接给对象赋值
-->
</beans>

调用并生成JAVABean

//获取Spring对象的上下文

ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

HelloSpring helloSpring = (HelloSpring) context.getBean("helloSpring");
System.out.println(helloSpring.toString());

Spring_IOC_Xml配置

原文:https://www.cnblogs.com/8023cyy/p/14887709.html

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