[java web]Idea+maven+spring4+hibernate5+struts2整合过程

摘要

最近也在网上找了些教程,试着使用maven进行包依赖关系的管理,也尝试着通过注解的方式来整合ssh框架。在这个过程中,踩了不少的坑。折腾很长时间,才算把架子折腾起来。这里把结果整理下,作为以后工作中的参考。

项目结构

关于maven如何使用,可自行搜索,默认你有一定的maven基础。maven建议中央仓库配置成阿里云的,可以下载速度快一些。地址

1、开始之前,需要通过maven进行ssh jar包引入。可以参考下面的pom.xml

2、将resources设置为资源目录,并添加如上图所示的jdbc属性文件,struts2配置文件,日志属性文件,spring配置文件

内容分别如下:

3、三层结构,以及注解的使用

4、web

5、配置tomcat服务器,然后启动即可,会自动生成数据库表结构(前提自己手动创建好数据库)

6、测试

总结

1、虽然网络上这样的文章很多,但自己动手实现,发现还是有很多错误,发现最多的是,由jar的版本问题引起的,比如在配置问价中org.springframework.orm.hibernate5.LocalSessionFactoryBean这个类所在的包,在hibernate3,4,5中都有,如果你在配置文件中所写的,和HibernateDaoSupport所使用的包版本不一致,就会出错。

2、,方言的配置,hibernate关于mysql的方言就有三个,这里采用MySQL5Dialect。

3、然后就是事务了,采用事务的注解,需要在配置文件中进行配置事务管理器。

annotation-driven:

这是xsd中 对事务管理器的描述。

The default annotations supported are Spring's @Transactional and EJB3's @TransactionAttribute (if available). Transaction semantics such as propagation settings,the isolation level,the rollback rules,etc are all defined in the annotation metadata. See org.springframework.transaction.annotation.EnableTransactionManagement Javadoc for information on code-based alternatives to this XML element. ]]></span><span style="color: #0000ff;"&gt;</</span><span style="color: #800000;"&gt;xsd:documentation</span><span style="color: #0000ff;"&gt;></span> <span style="color: #0000ff;"&gt;</</span><span style="color: #800000;"&gt;xsd:annotation</span><span style="color: #0000ff;"&gt;></span> <span style="color: #0000ff;"&gt;<</span><span style="color: #800000;"&gt;xsd:attribute </span><span style="color: #ff0000;"&gt;name</span><span style="color: #0000ff;"&gt;="transaction-manager"</span><span style="color: #ff0000;"&gt; type</span><span style="color: #0000ff;"&gt;="xsd:string"</span><span style="color: #ff0000;"&gt; default</span><span style="color: #0000ff;"&gt;="transactionManager"</span><span style="color: #0000ff;"&gt;></span> <span style="color: #0000ff;"&gt;<</span><span style="color: #800000;"&gt;xsd:annotation</span><span style="color: #0000ff;"&gt;></span> <span style="color: #0000ff;"&gt;<</span><span style="color: #800000;"&gt;xsd:documentation </span><span style="color: #ff0000;"&gt;source</span><span style="color: #0000ff;"&gt;="java:org.springframework.transaction.PlatformTransactionManager"</span><span style="color: #0000ff;"&gt;></span><span style="color: #0000ff;"&gt;<![CDATA[</span><span style="color: #808080;"&gt; The bean name of the PlatformTransactionManager that is to be used to drive transactions. This attribute is not required,and only needs to be specified explicitly if the bean name of the desired PlatformTransactionManager is not 'transactionManager'.</span></pre>

4、一定要有耐心。一个个解决问题,也是一种积累。

相关文章

这篇文章主要介绍了idea中mapper快速跳转到xml插件的方法,具...
今天小编给大家分享的是IDEA搭建Maven模块化项目的实现方法,...
这篇文章主要介绍了ideaintellij怎么快速修复if语句缺少大括...
这篇文章主要介绍“idea运行main方法或Test避免编译整个应用...
这篇文章主要介绍“idea项目全局去掉严格的语法校验方式是什...
本文小编为大家详细介绍“Windows、IDEA、VSCode常用快捷键有...