SSH或SHSpringMVC下采用spring的Annotation配置dao,service,controller(便于团队开发,各自修改自己的annotation)
2014-03-23 23:35
573 查看
使用此功能的前提必须是Spring3.0或以上版本。
在和数据库连接的spring配置文件中修改,此文的项目基础来源于http://blog.csdn.net/needkane/article/details/21410805
我们在applicationContext-hibernate.xml修改
从头一行开始
<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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd">
加入下面的配置,设置允许使用Annotation,并设置Annotation作用的包范围,其中要包括dao.impl,service.impl和action。
<context:annotation-config></context:annotation-config>
<context:component-scan
base-package="com.kane.action,com.kane.back.service.impl,com.kane.dao.impl">
</context:component-scan>
接下来数据源等配置和以前一样,这样代替了xml配置
dao.impl类的声明
// 表示该类自动配置成为一个Spring的<bean>,id为类名首字母小写
@Component
service类的声明
@Service
action类的声明
// 也表示是一个<bean>
@Controller
// 不使用单例设计
@Scope(value =
"prototype")
在和数据库连接的spring配置文件中修改,此文的项目基础来源于http://blog.csdn.net/needkane/article/details/21410805
我们在applicationContext-hibernate.xml修改
从头一行开始
<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"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd">
加入下面的配置,设置允许使用Annotation,并设置Annotation作用的包范围,其中要包括dao.impl,service.impl和action。
<context:annotation-config></context:annotation-config>
<context:component-scan
base-package="com.kane.action,com.kane.back.service.impl,com.kane.dao.impl">
</context:component-scan>
接下来数据源等配置和以前一样,这样代替了xml配置
dao.impl类的声明
// 表示该类自动配置成为一个Spring的<bean>,id为类名首字母小写
@Component
service类的声明
@Service
action类的声明
// 也表示是一个<bean>
@Controller
// 不使用单例设计
@Scope(value =
"prototype")
相关文章推荐
- Spring3 Mybatis3 freemarker 自动生成对应表的model、mapper、service、controller并自动修改mybatis配置文件
- Spring2.5中annotation配置中@Override、@Component、 @Controller、 @Service、 @Repository、@Autowired的解析
- Spring的事务到底该给Dao配置还是给Service配置
- Spring Cloud Config 的坑:以ssh方式从自己搭建的 git repository 取配置文件
- 使用spring注解@Controller @Service @Repository简化配置
- Spring的Dao Service采用单例模式+ThreadLoca模式实现线程安全
- Spring的事务到底该给Dao配置还是给Service配置
- Spring-Security (学习记录五)--配置登录时,密码采用md5加密,以及获取登录信息属性监听同步自己想要的登录信息
- 【springmvc+mybatis项目实战】杰信商贸-5.生产厂家DAO+SERVICE+CONTROLLER+JSP+配置文件
- Spring的事务到底该给Dao配置还是给Service配置?
- Spring的事务到底该给Dao配置还是给Service配置?
- 使用Spring的@Autowired 实现DAO, Service, Controller三层的注入(转)
- SSH框架联合开发(Annotation精简Spring的配置文件)
- Spring对Controller、Service、Dao进行Junit单元测试总结
- action,dao和service在spring中的配置
- 使用spring注解@Controller @Service @Repository简化配置
- day76_maven02:maven拆分各层配置后,【pom.xml、Spring配置都按层拆分(dao/service/action)】,导致报错解决。
- Spring的事务关于配置到service和dao中的区别
- Spring学习-11:配置文件引入的问题(配置文件过于庞大,不便于修改的处理方法)
- mybatis3整合spring4-采用mapper动态代理的方式开发Dao