资源预览内容
第1页 / 共16页
第2页 / 共16页
第3页 / 共16页
第4页 / 共16页
第5页 / 共16页
第6页 / 共16页
第7页 / 共16页
第8页 / 共16页
第9页 / 共16页
第10页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
spring:业务层框架,管理bean的,核心组件是容器。spring方式打印helloworld业务类:GreetingService.javapackage com.spring.demo.spring1;/* * author xuyh * date 2013-6-18 下午11:16:06 * version v1.0 * description 问候服务类 */public class GreetingService private String greeting;public String getGreeting() return greeting;public void setGreeting(String greeting) this.greeting = greeting;public void sayHello() System.out.println(hello: + greeting);maven配置文件: pom.xml4.0.0com.spring.demospring10.0.1-SNAPSHOTjarspring1http:/maven.apache.orgUTF-8junitjunit4.11org.springframeworkspring-core3.1.4.RELEASEorg.springframeworkspring-beans3.1.4.RELEASEorg.springframeworkspring-aop3.1.4.RELEASEorg.springframeworkspring-context3.1.4.RELEASESpring 配置文件:ApplicationContext.xml测试类 : GreetingServiceTestpackage com.spring.demo.spring1;import org.junit.Test;import org.springframework.beans.factory.BeanFactory;import org.springframework.context.support.ClassPathXmlApplicationContext;public class GreetingServiceTest /* 传统方式打印helloworld */Testpublic void testSayHello() GreetingService gs = new GreetingService();gs.setGreeting(xuyh);gs.sayHello();/* spring方式打印helloworld */Testpublic void testSayHelloSpring() BeanFactory bf = new ClassPathXmlApplicationContext(ApplicationContext.xml);GreetingService gs = (GreetingService) bf.getBean(greetingService);gs.sayHello();更多的属性或对象package com.spring.demo.spring1;/* * author xuyh * date 2013-6-18 下午11:16:06 * version v1.0 * description 问候服务类 */public class GreetingService private String greeting;private String greeting2;private ByeService byeService;public String getGreeting() return greeting;public void setGreeting(String greeting) this.greeting = greeting;public void sayHello() System.out.println(hello: + greeting);public String getGreeting2() return greeting2;public void setGreeting2(String greeting2) this.greeting2 = greeting2;public void sayHello2() System.out.println(hello: + greeting2);public ByeService getByeService() return byeService;public void setByeService(ByeService byeService) this.byeService = byeService;public void sayGreetingBye()byeService.sayBye();package com.spring.demo.spring1;/* * author xuyh * date 2013-6-18 下午11:16:06 * version v1.0 * description 欢送服务类 */public class ByeService private String bye;public String getBye() return bye;public void setBye(String greeting) this.bye = greeting;public void sayBye() System.out.println(bye: + bye);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号