SSH环境搭建之Spring环境搭建篇
2024-09-02 15:38:41
SSH环境搭建之Spring环境搭建篇
一、引入Spring所使用的JAR文件
二、在src目录下创建beans.xml(Spring的容器文件)
<?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: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-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> </beans>
三、创建测试类并测试
1.实体类 TestService.java
package com.xiaonei.test; /**
* Created by zhangshengjian on 2017/1/19.
*/
public class TestService { private String name; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
2.将实体类对应内容配置到beans.xml文件中
<bean id="testService" class="com.xiaonei.test.TestService">
<property name="name" value="ok"/>
</bean>
3.测试类 TestApp.java
package com.xiaonei.test; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by zhangshengjian on 2017/1/19.
*/
public class TestApp { public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
TestService testService = (TestService) ac.getBean("testService");
System.out.println(testService.getName());
}
}
4.测试结果
最新文章
- [No0000AD]7z源码完全移植至Visual Studio 2015
- unrecognized selector sent to instance
- AWS-CDH5.5安装-安装
- nginx之location
- HTTP Basic Authentication
- [改善Java代码]覆写equals方法时不要识别不出自己
- exit和abort都是用来终止程序的函数
- Linux学习之第十九、条件判断
- 初识google多语言通信框架gRPC系列(三)C#中使用gRPC
- String、StringBuffer、与StringBuilder的区别
- Css(常用的特殊效果)
- hive中left/right join on连接中and与where的使用问题
- hyperscan简单学习(2)
- day05 数据基本类型及内置方法:字符串str、列表list
- 奇怪吸引子---LiuChen
- 怎样从外网访问内网WebLogic?
- 在thinkphp里面执行原生的sql语句
- 计算概论(A)/基础编程练习1(8题)/5:鸡兔同笼
- config配置中心之自动刷新
- Oracle中查询主键、外键、sequence、表基本信息等