SSH框架联合开发(Annotation精简Spring的配置文件)
来源:互联网 发布:我们应该禁止网络用语 编辑:程序博客网 时间:2024/06/03 21:27
配置信息的改变
在Spring3.0及以上版本中,可以使用Annotation替代一部分XML配置,从而简化一些配置代码。
使用此功能前,需要先在头信息中加入允许使用context支持的配置。(这里头信息是在初始创建的applicationContext中,我这里是在application-hibernate,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"
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
xsi:schemaLocation="http://www.springframework.org/schema/bean
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
原来的配置信息:
<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-3.0.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan
base-package="org.liky.ssh.dao.impl,org.liky.ssh.back.service.impl,org.liky.ssh.back.action"></context:component-scan>
DAO层
@Componentpublic class NewsDAOImpl extends HibernateDaoSupport implements INewsDAO {@Autowiredpublic NewsDAOImpl(HibernateTemplate hibernateTemplate) {super.setHibernateTemplate(hibernateTemplate);}
Service层
@Service
public class NewsServiceImpl implements INewsService {
•••••@Resource(name="newsDAOImpl")public void setNewsdao(INewsDAO newsdao) {this.newsdao = newsdao;}@Resource(name = "newsTypeDAOImpl")public void setTypedao(INewsTypeDAO typedao) {this.typedao = typedao;}
Action配置
这里的Controller也是一个bean,在setService注入的时,resource引用newsService,很好理解的
- <div style="text-align: justify;"><span style="font-size:14px;"><span style="color:#000099;">@Controller
- public class NewsAction extends ActionSupport {
- </span></span></div>
- <div style="text-align: justify;"><span style="font-size:14px;"><span style="color:#000099;">@Resource(name="newsServiceImpl")</span></span></div>
- <div style="text-align: justify;"><span style="font-size:14px;"><span style="color:#000099;">public void setService(INewsService service) {</span></span></div>
- <div style="text-align: justify;"><span style="font-size:14px;"><span style="color:#000099;">this.service = service;</span></span></div>
- <div style="text-align: justify;"><span style="font-size:14px;"><span style="color:#000099;">}</span></span></div>
总结:Spring的Annotation确实精简了配置文件,它不像hibernate的annotation只是在映射文件体现,
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- SSH框架联合开发(Annotation精简Spring的配置文件)
- SSH框架联合开发(Annotation精简Spring的配置文件)
- SSH联合开发环境的 搭建
- SSH之 spring框架配置文件
- 基于注解的ssh框架之spring配置文件
- Spring + JDBC + Struts联合开发(实现单表的CRUD)
- Spring + JDBC + Struts联合开发(实现单表的CRUD)
- Spring Annotation(注解)的使用步骤(SSH)
- 整合ssh框架的配置文件
- 框架SSH整合的配置文件
- ssh框架配置文件的作用
- annotation 简化spring的配置文件bean
- spring 框架的配置文件
- compass+SSH 的spring配置文件
- SSH下的Spring配置文件
- 搭建SSH框架遇到的struts.xml找不到spring定义的bean的错误(配置文件的路径问题)
- SSH框架学习语录三:Struts2+Spring, 将框架的配置文件整合起来
- SSH框架系列:Spring读取配置文件以及获取Spring注入的Bean
- java.io.FileNotFoundException: /home/hadoop/hadoop/dfs/namenode/current/VERSION (Permission denied)
- 【一图解读】甜粽子VS咸粽子 你吃哪个?
- 第 3 章 单例模式
- Spring + Struts + Hibernate联合开发(多对一关系)
- day82(断言)
- SSH框架联合开发(Annotation精简Spring的配置文件)
- perl智能匹配
- 第 4 章 多例模式
- Tomcat7和mysql连接池的配置方法和测试
- OCP 1Z0 051 QUESTION NO: 16
- object-c开发命名规则
- Application.Exit()和this.close()的区别
- Spring + JDBC + Struts联合开发(实现单表的CRUD)
- 逆向工程第002篇:打造自己的仙剑奇侠