Spring In Action-学习(1)

1、依赖包
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.aspects-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.context.support-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.instrument-3.0.5.RELEASE.jar
org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.jms-3.0.5.RELEASE.jar
org.springframework.orm-3.0.5.RELEASE.jar
org.springframework.oxm-3.0.5.RELEASE.jar
org.springframework.spring-library-3.0.5.RELEASE.libd
org.springframework.test-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.portlet-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar
org.springframework.web.struts-3.0.5.RELEASE.jar
commons-logging.jar (注意)

 

2、GreetService.java

package wuyechun.hellomyspring;

public interface GreetService {
	public void sayGreeting();
}

 

3、GreetingServiceImpl.java

package wuyechun.hellomyspring;

public class GreetingServiceImpl implements GreetService {

	private String greeting;

	public GreetingServiceImpl() {

	}

	public String getGreeting() {
		return greeting;
	}

	public void setGreeting(String greeting) {
		this.greeting = greeting;
	}

	@Override
	public void sayGreeting() {

		System.out.println(greeting);

	}

}

 

3、 hello.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-3.0.xsd">

	<bean id="GreetingServiceImpl" class="wuyechun.hellomyspring.GreetingServiceImpl">
	<property name="greeting">
	<value>HelloWorld!</value>
	</property>
	</bean>

</beans>

 

4、HelloApp.java

package wuyechun.hellomyspring;
import java.io.FileNotFoundException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloApp {
	public static void main(String[] args) throws FileNotFoundException {

		String filePath = "/wuyechun/hellomyspring/hello.xml";
		BeanFactory factory = new ClassPathXmlApplicationContext(filePath);
		GreetingServiceImpl serviceImpl = (GreetingServiceImpl) factory
				.getBean("GreetingServiceImpl");
		serviceImpl.sayGreeting();

	}
}

 

5、截图 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值