spring-spring的配置
来源:互联网 发布:歌斐资产 知乎 编辑:程序博客网 时间:2024/06/04 20:04
applicationContext.xml:
<!-- 引入我们的db.properties --><context:property-placeholder location="classpath:com/dispatch/db.properties"/><?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!-- 引入我们的db.properties --><context:property-placeholder location="classpath:com/dispatch/db.properties"/>
<!-- 字容器中配置bean --><!-- bean元素的作用是,当我们的spring框架加载的时候,spring就会自动的创建一个bean对象,并放入内存UserService userService=new UserService(); --><bean id="userService" class="com.service.UserService"><property name="name"><value>Han</value></property><!-- 在userService中引用 byeService --><property name="byeService" ref="byeService"></property></bean><bean id="byeService" class="com.service.ByeService"><property name="name" value="小明"/></bean></beans>ByeService.java:
package com.service;public class ByeService {private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public void sayBye(){System.out.println("bye,"+name);}}UserService.java
package com.service;public class UserService {private String name;private ByeService byeService;public ByeService getByeService() {return byeService;}public void setByeService(ByeService byeService) {this.byeService = byeService;}public String getName() {return name;}public void setName(String name) {this.name = name;}public void sayHello(){System.out.println("hello,"+name);byeService.sayBye();}}
test.java:
package com.test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.service.*;import com.util.ApplicationContextUtil;public class test {public static void main(String[] args) {// TODO Auto-generated method stub//1.得到spring的applicationContext对象(容器对象)//ApplicationContext ac=ApplicationContextUtil.getApplicationContext();//UserService us=(UserService) ac.getBean("userService");//us.sayHello();//ByeService bs=(ByeService) ac.getBean("byeService");//bs.sayBye();}}
阅读全文
0 0
- spring-spring的配置
- spring bean的配置
- 配置Spring的方法
- Spring 事务管理的配置
- spring+hibernate的配置
- spring定时器的配置
- 配置spring的事务管理
- Spring Security的配置
- Spring的事务配置
- spring的 PropertyPlaceholderConfigurer配置
- spring的配置
- Spring常用的配置
- spring的AOP配置
- Spring的dataSource配置
- spring 事务管理的配置
- Spring的AOP配置
- spring的maven配置
- spring+activemq的配置
- 稳定排序和不稳定排序
- 模拟SQLServer登录 获取所有数据库实例
- Java开发一款高并发埋点日志上传服务器
- STL 中 sort()函数用法详解—— 排序
- C语言内存布局
- spring-spring的配置
- 最长递增子序列
- Shell定时删除指定时间之前的文件
- DHCP设置之起始地址与结束地址
- 78. Subsets
- dom4j的详解
- HDFS-HA-federation的机制和功能组件
- Java常见面试题—GC垃圾收集器
- 程序员面试金典(4):空格替换(python)