您的位置:首页 > 编程语言 > Java开发

Spring开发步骤

2016-10-01 17:26 127 查看

1.Spring介绍

Spring是一种可以解决对象创建和处理对象依赖关系的一种框架,可以和其他框架 一起使用。

2.spring开发步骤

2.1spring对象层次图

2.2步骤

2.2.1引入jar包

五个必须映入的jar文件commons-logging-1.1.3.jar           日志spring-beans-3.2.5.RELEASE.jar       bean节点spring-context-3.2.5.RELEASE.jar      spring上下文节点spring-core-3.2.5.RELEASE.jar        spring核心功能spring-expression-3.2.5.RELEASE.jar   spring表达式相关表

2.2.2写配置文件

核心配置文件:applicationContext.xml
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
 <bean id="user2" class="cn.itcast.b_create_obj.User">
</bean>
</beans>
bean节点下的id:对象名bean节点下的class:类的全路径

2.2.3创建IOC对象

public void testAc() throws Exception {// 得到IOC容器对象ApplicationContext ac = new ClassPathXmlApplicationContext("cn/itcast/a_hello/applicationContext.xml");// 从容器中获取beanUser user = (User) ac.getBean("user");System.out.println(user);}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring