①.新建一个maven项目
②.从maven官网导入spring的三个包(最好统一spring的jar版本,我这里用的是4.3.18)
![](https://img.haomeiwen.com/i8687382/58b4d29043d45159.png)
③.配置spring
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
">
<bean id="person" class="com.theme.springdemo.beans.Person"></bean>
</beans>
④.写实现类
⑤写测试类
spring mvc结构:
![](https://img.haomeiwen.com/i8687382/88a4c105edf29b9a.png)
小知识(spring中的ref使用方法):
spring的配置文件可能会有多个
<property name="a" ref="b" />就是找当前配置文件里的bean 也就是b
<ref bean ="b"/> 是寻找全局中的 bean;
网友评论