只是一个最最基本的helloworld。学了Spring就没有用过。。现在回头看了看。。做了一个helloworld
c3p0-0.9.1.2.jar
commons-logging-1.1.1.jar
mysql-connector-java-5.1.7-bin.jar
spring-aop-4.0.0.RELEASE.jar
spring-beans-4.0.0.RELEASE.jar
spring-context-4.0.0.RELEASE.jar
spring-core-4.0.0.RELEASE.jar
spring-expression-4.0.0.RELEASE.jar
public class HelloWorld { private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public void log(){ System.out.println(">>>>>>>>>"+message); } }
public class Test { public static void main(String[] args) { //创建Spring的IOC容器 ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml"); //从容器中获取bean HelloWorld hw=(HelloWorld)ac.getBean("helloWorld"); hw.log(); } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- id标识 class全类名 property:setMessage--> <bean id="helloWorld" class="com.test.HelloWorld"> <property name="message" value="hahaha"></property> </bean> </beans>
时间: 2024-11-05 02:41:41