提交 e0430717 编写于 作者: 武汉红喜's avatar 武汉红喜

TestSpring

上级 a51a6566
package com.whatsmars.mars001.web.spring;
/**
* Created by shenhongxi on 2016/4/7.
*/
public class Mars {
private long age;
private String cnName;
public long getAge() {
return age;
}
public void setAge(long age) {
this.age = age;
}
public String getCnName() {
return cnName;
}
public void setCnName(String cnName) {
this.cnName = cnName;
}
}
package com.whatsmars.mars001.web.spring;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Created by shenhongxi on 2016/4/7.
*/
public class TestSpring {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-test.xml");
Mars mars = (Mars) context.getBean("mars");
System.out.println(mars.getAge());
System.out.println(mars.getCnName());
}
}
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-autowire="byName">
<bean id="mars" class="com.whatsmars.mars001.web.spring.Mars">
<property name="age" value="45" />
<property name="cnName" value="火星" />
</bean>
</beans>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册