Spring

2019-03-17  本文已影响0人  山不转人自转

①.新建一个maven项目
②.从maven官网导入spring的三个包(最好统一spring的jar版本,我这里用的是4.3.18)


image.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结构:


image.png

小知识(spring中的ref使用方法):
spring的配置文件可能会有多个
<property name="a" ref="b" />就是找当前配置文件里的bean 也就是b
<ref bean ="b"/> 是寻找全局中的 bean;

上一篇下一篇

猜你喜欢

热点阅读