将
<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
</beans>
放入配置文件中
这样我们就得到了context命名空间
使用<context:component-scan base-package="com.xf"></context:component-scan>
这样就可以扫描到全部的注解
之后我们就可以在bean文件上面加component了
从component衍生出来了三个注解
Controller
Service
Repository
他们的功能是完全一样的,之所以这样写是为了让三层逻辑更加清晰,
Controller对应表现层
Service对应业务层
Repository对应持久层