首页 > 代码库 > Spring 框架的环境搭建
Spring 框架的环境搭建
Spring 的环境搭建
Spring 现在流行的SSH框架之一,主要用于解决主业务之间的耦合度问题 Spring主要负责应用中对对象的创建,初始化,销毁,关系维护,降低代码耦合
主要提供了两个降低耦合度的方式:
IOC(控制反转)
主业务在相互调用的过程中不再需要自行创建对象,由spring自动注入
AOP(面向切面编程)
Spring 容器统一完成系统级服务,降低了系统级服务与主服务
配置框架第一步
下载Spring Jar包
官网: http://spring.io/
软件仓库: http://repo.spring.io http://search.maven.org/
配置框架第二步
创建项目导入项目所需要的基础包
配置框架第三步
编写简单的接口和实现类
Public interface hello{ Void hello(); } Public class helloWrod implements hello{ Public void hello(){ System.out.println(“hello Spring”); } }
配置框架第四步
配置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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- id="自定义命名" classs="实现类的路径" --> <bean id="managerService" class="demo1.UserDaoImp" /> <bean class="BeanCL.MyBeanPostPro" /> </beans>
配置框架第五步
public void test2(){ ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); IManagerService ism = (IManagerService)ac.getBean("managerService"); ism.hello(); }
Spring 框架的环境搭建
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。