spring配置
来源:互联网 发布:廊坊数控编程招聘信息 编辑:程序博客网 时间:2024/05/16 06:51
下载spring插件
点击下载
然后maven导入spring jar
<!-- 引入Spring依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.10.RELEASE</version>
</dependency>
//如何使用
第一步
写一个实体类
Student
第二步
配置student
写一个spring.xml
配置:
<!-- class是实体类的全限定名字-->
<bean id="student" class="com.zking.entity.Student">
<property name="yx" ref="Yxintent">
<!-- name实体类的属性名字 value是值 ref是导入一个对象(实体类)-->
</property>
<property name="mw" ref="Mwintent"></property>
<property name="实体类的属性" value="值"></property>
<property name="pf" ref="PfIntent"></property>
</bean>
执行:
两种方法
//1.加载spring配置文件
//1.1 延迟加载(懒加载)
<!-- 你写的xml getBean("student");是你之前配置的名字-->
BeanFactory bf=new XmlBeanFactory(new ClassPathResource("applicationcontext.xml"));
<!-- 你要执行的类-->
Student student=(Student) bf.getBean("student");
System.out.println(student);
//1.2及时加载
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
Person person=(Person) ac.getBean("person");
- Spring配置
- 配置spring
- Spring 配置
- spring配置
- Spring配置
- spring配置
- Spring配置
- spring 配置
- spring配置
- Spring配置
- spring 配置
- spring 配置
- Spring配置
- spring配置
- spring配置
- spring配置
- spring 配置
- Spring 配置
- python基础2
- wget用法汇总
- centOS-7.0安装与配置Tomcat7.0及JDK1.7
- 洛谷P1894 [USACO4.2]完美的牛栏The Perfect Stall
- JavaScript动画
- spring配置
- BZOJ 4514 浅谈最大费用最大流
- DSYMTools
- col
- 没有题目
- Unity游戏开发网络基础(3)
- 移动端gpu hack
- 面向对象基础知识(4)
- Hadoop7-HDFS的NameNode的元数据管理机制与Hadoop的高可用架构