当前位置: 代码迷 >> Web前端 >> Spring In Action-学习(一)
  详细解决方案

Spring In Action-学习(一)

热度:140   发布时间:2012-09-03 09:48:39.0
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、截图?

  相关解决方案