Java Spring框架入门第一个小例子教程

IDE:Eclipse

1.首先创建一个Dynamic Web Project

2.在WebContent/WEB-INF/lib文件夹下导入如下几个包(下载链接:)

3.选中这6个包,右键BuildPath->Add to Build Path

4.在Java Resource/src下创建包

5.在包下创建两个类:①Hello.java ②MainApp.java

①创建一个成员属性,并为其创建getter/setter方法

②在MainApp.java下设置main方法并加入代码

6.在src目录下创建pom.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" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="hello" class="com.ly.test.Hello"> </bean> </beans>

7.在MainApp下运行Main方法,控制台输出如下

此时的项目目录如下

经验分享 程序员 微信小程序 职场和发展