spring配置Dem
来源:互联网 发布:种姓制度 知乎 编辑:程序博客网 时间:2024/06/03 20:42
一。在eclipse新建项目,导入jar包
二 在XML内的配置
<context-param>
<param-name>contextConfigLocation</param-name>
//或都 这样 <param-value>classpath*:config/spring*.xml</param-value>
<param-value>classpath:</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
三。创建一个bean
public class UserDemo {
private int id;
private String name;
public UserDemo(int id, String name) {
super();
this.id = id;
this.name = name;
}
public UserDemo() {
super();
// TODO Auto-generated constructor stub
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
四。在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" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="user" class="test.UserDemo">
<property name="id" value="12"></property>
<property name="name" value="name"></property>
</bean>
</beans>
五 测试连接是否成功
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class test {
private ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
@Test
public void test(){
UserDemo userDemo=(UserDemo) ac.getBean("user");
System.out.println(userDemo.getId()+userDemo.getName());
}
}
- spring配置Dem
- DEM
- DEM data
- 三维dem
- WorldWind系列十五:如何切割影像和DEM数据及其在WW中的应用配置
- WorldWind学习系列十五:如何切割影像和DEM数据及其在WW中的应用配置
- VS2010+OGRE1.9+OGRE工程库配置&提取影像和DEM的途径
- Spring配置
- 配置spring
- Spring 配置
- spring配置
- Spring配置
- spring配置
- Spring配置
- spring 配置
- spring配置
- Spring配置
- spring 配置
- Future+Callable提供系统吞吐量
- HDU1530:Maximum Clique(最大团)
- Java学习清单
- 520. Detect Capital
- Java项目经验
- spring配置Dem
- Linux下的通讯录项目
- HDU 3584 Cube(三维树状数组)
- AutoCAD文档03——常见问题01.消失的菜单栏
- tensorflow 入门之 hello tensorflow
- 安卓intent隐式跳转
- 重新开始学习.NET之一--ref参数和out参数
- tensorflow 笔记
- 阮一峰博客转载记录