Welcome 微信登录

首页 / 软件开发 / JAVA / spring入门(2)--写在第一个案例前

spring入门(2)--写在第一个案例前2013-07-18 csdn 史国旭1、引入spring的jar文件

libs/spring-beans-3.2.2.RELEASE.jar

libs/spring-context-3.2.2.RELEASE.jar

libs/spring-context-support-3.2.2.RELEASE.jar

libs/spring-core-3.2.2.RELEASE.jar

libs/spring-expression-3.2.2.RELEASE.jar

需要:

commons-logging-1.1.1.jar

2、需要添加spring的配置文件

配置文件的名称可以随便起名,但是最好有实际意义。

例如:

spring-dao.xml

spring-service.xml

spring.xml

3、spring配置文件 怎么引入 beans约束

---spring-framework-3.2.2.RELEASE-dist/spring-framework-3.2.2.RELEASE/docs/spring-framework-reference/html/index.html

目录中:

5.2.1. Configuration metadata 点击进去

可以拷贝原信息:

<?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

http://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

4、下面就有实例化 :容器

// 读取 classes 路径下面的文件 参数 动态参数、单个参数、数组 、可以使用通配符等

ApplicationContext context = new ClassPathXmlApplicationContext(

"spring.xml");