一紊馏、Maven配置
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.huangyian</groupId>
<artifactId>firstmaven</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
</dependencies>
</project>
二、一個(gè)簡(jiǎn)單的 Spring bean
1蒲犬、Bean類(lèi)
package tg.export;
public class GoodsExport {
private Integer id;
/**
* 實(shí)現(xiàn)方法
* @return
*/
public Integer addGoods() {
return this.id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
2朱监、Spring bean 配置文件
<?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.xsd">
<bean id="GoodsExport" class="tg.export.GoodsExport">
<property name="id" value="5" />
</bean>
</beans>
3、執(zhí)行代碼
public class App {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"config/applicationContext.xml");
GoodsExport obj = (GoodsExport) context.getBean("GoodsExport");
System.out.println(obj.addGoods());
}
}
4原叮、結(jié)果為5
5
Process finished with exit code 0