记录一下Maven整合spring,hibernate,strusts2我程序中出的bug
action类如下
package com.itheima.movenweb.action; import java.util.List; import org.apache.struts2.ServletActionContext;
import org.junit.Test; import com.itheima.movenweb.domain.Dep;
import com.itheima.movenweb.service.Service;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven; public class Action extends ActionSupport { private Service service; public Service getService() {
return service;
}
public void setService(Service service) {
this.service = service;
}
public String findDepList(){
System.out.println(1);
List<Dep> list = service.dolist();
System.out.println(service);
ServletActionContext.getRequest().setAttribute("list", list);
return "success";
} }
serviceImpl如下:
package com.itheima.movenweb.serviceImpl; import java.util.List; import org.junit.Test; import com.itheima.movenweb.dao.Dao;
import com.itheima.movenweb.domain.Dep;
import com.itheima.movenweb.service.Service; public class ServiceImpl implements Service { private Dao dao; public Dao getDao() {
return dao;
} public void setDao(Dao dao) {
this.dao = dao;
} @Override
public List<Dep> dolist() {
System.out.println(2);
List<Dep> list = dao.dolist();
return list;
} }
daoImpl如下:
package com.itheima.movenweb.daoImpl; import java.util.List; import org.springframework.orm.hibernate5.support.HibernateDaoSupport; import com.itheima.movenweb.dao.Dao;
import com.itheima.movenweb.domain.Dep; public class DaoImpl extends HibernateDaoSupport implements Dao{ @Override
public List<Dep> dolist() {
System.out.println(3);
List<Dep> list = (List<Dep>) this.getHibernateTemplate().find("from Dep");
return list;
} }
applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
"> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!-- 在这里方法上开启事务,不要搞错了 -->
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="list" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut id="serviceMethod" expression="execution(* com.itheima.movenweb.serviceImpl.*.*(..))"/>
<aop:advisor pointcut-ref="serviceMethod" advice-ref="advice" />
</aop:config> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<!--
<property name="url" value="jdbc:mysql://127.0.0.1:3306/movenwebtest?useUnicode=true&characterEncoding=UTF8"/>
-->
<property name="url" value="jdbc:mysql:///movenwebtest11?useUnicode=true&characterEncoding=UTF8"/>
<property name="username" value="root"/>
<property name="password" value="123"/>
</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
</props>
</property>
<property name="mappingLocations">
<value>classpath:com/itheima/movenweb/domain/*.hbm.xml</value>
</property>
</bean> <!-- 部门数据访问类 -->
<bean id="depDao" class="com.itheima.movenweb.daoImpl.DaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 部门业务逻辑类 -->
<bean id="depService" class="com.itheima.movenweb.serviceImpl.ServiceImpl">
<property name="dao" ref="depDao"></property>
</bean> <!-- 部门action -->
<bean id="depAction" class="com.itheima.movenweb.action.Action">
<property name="service" ref="depService"></property>
</bean> </beans>
struts.xml 如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="index" class="depAction" method="findDepList">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
还有hibernate的配置文件,我报错的原因和他没有关系,我就不放在这里了;以上的代码是修改后正确的代码;
下面我放入我错误的代码,第一个错误在struts2的配置文件,我将class的配置信息配成了类的全路径,然后报空指针异常,这里class的路径应该写已经配置在applicationContext.xml中的action的id的值
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="index" class="com.itheima.movenweb.domain.Dep" method="findDepList">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
然后又出了一个问题:如下
我的action中的输出语句输出了,但是我的数据库没有连接上,我去查询我的数据库,发现我的数据库名字是“mavenwebtest11;” 对,你没有看错,我的数据库名字多加了“;”我发现我在创建数据库后本来是想加上英文状态的结束符号,结果加成了中文的结束符号,然后就被一起写进了数据库的名字中,大写的尴尬呀,作为我的第一篇博客,谨以此来激励自己不断学习,不断成长
记录一下Maven整合spring,hibernate,strusts2我程序中出的bug的更多相关文章
- springboot+maven整合spring security
springboot+maven整合spring security已经做了两次了,然而还是不太熟悉,这里针对后台简单记录一下需要做哪些事情,具体的步骤怎么操作网上都有,不再赘述.1.pom.xml中添 ...
- Maven 整合 spring profile实现多环境自动切换
Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...
- eclipse环境下基于已构建struts2项目整合spring+hibernate
本文是基于已构建的struts2项目基础上整合 spring+hibernate,若读者还不熟悉struts2项目,请先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 ...
- 使用maven整合spring+springmvc+mybatis
使用maven整合spring+springmvc+mybatis 开发环境: 1. jdk1.8 2. eclipse4.7.0 (Oxygen) 3. mysql 5.7 在pom.xml文件中, ...
- Maven整合Spring与Solr
首先,在maven的pom.xml文件中配置对spring和solrj客户端的依赖: <project xmlns="http://maven.apache.org/POM/4.0.0 ...
- 借助Maven入手Spring Boot第一个程序
目前网上有不少Spring Boot的入门文章,都很有帮助,本人最近在深入学习Spring Cloud,在搭建第一个Hello World程序时,感觉对于新手而言,介绍文章怎么详细都不为过,因为其中坑 ...
- jersey2 整合 spring + hibernate + log4j2
整合 spring jersey2 官方还未正式支持 spring4, 但网上有好多支持方案,折腾了一圈后,还是用了 spring3; pom 添加以下依赖配置 <!-- Spring --&g ...
- maven学习记录三——maven整合ssh框架
6 整合ssh框架 6.1 依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar, 这种情况 叫 依赖传递 6.2 依赖版本冲突的解决 1. 第 ...
- Maven配置Spring+Hibernate Shiro权限控制项目
前言:在Eclipse中安装好Maven插件,然后创建一个Sample项目.在Eclipse中检出Shiro的官方演示样例.地址http://svn.apache.org/repos/asf/shir ...
随机推荐
- iOS中 最新微信支付/最全的微信支付教程详解 韩俊强的博客
每日更新关注:http://weibo.com/hanjunqiang 新浪微博! 亲们, 首先让我们来看一下微信支付的流程吧. 1. 注册微信开放平台,创建应用获取appid,appSecret, ...
- 运用 三种 原生 谷歌 阿里 解析和生成json
三种类生成JSON数据方法 JSON(原生): 第一种 JSONStringer和JSONObject区别在于添加对象时是按顺序添加的比如说 JSONStringer 添加 a:1 b:2 c:3那么 ...
- SSH深度历险(七) 剖析SSH核心原理(一)
接触SSH有一段时间了,但是对于其原理,之前说不出来莫模模糊糊(不能使用自己的语言描述出来的就是没有掌握),在视频和GXPT学习,主要是实现了代码,一些原理性的内容还是欠缺的,这几天我自己也一直在反问 ...
- Android程序崩溃异常收集框架
最近在写Android程序崩溃异常处理,完成之后,稍加封装与大家分享. 我的思路是这样的,在程序崩溃之后,将异常信息保存到一个日志文件中,然后对该文件进行处理,比如发送到邮箱,或发送到服务器. 所以, ...
- PHP(PHP-FPM)手动编译安装
1安装PHP 1.1下载解压 wget http://museum.php.net/php5/php-5.3.5.tar.gz tarxzvf php-5.3.5.tar.gz cdphp-5.3.5 ...
- A*寻路算法入门(一)
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...
- 在CSDN开通博客专栏后如何发布文章(图文)
今天打开电脑登上CSDN发现自己授予了专栏勋章,有必要了解如何在专栏发布文章. 很感谢已经有前辈给出了图文教程,此文章转载自博客:http://blog.csdn.net/upi2u/article/ ...
- catalina.sh设置JAVA_HOME后还无法解决更换JDK有关问题
catalina.sh设置JAVA_HOME后还无法解决更换JDK问题 表示linux已经安装默认的JDK,需要查找配置文件,更换JDK路径为指定的路径 在root用户下 使用echo $PATH 查 ...
- 数据结构-自平衡二叉查找树(AVL)详解
介绍: 在计算机科学中,AVL树是最先发明的自平衡二叉查找树. 在AVL树中任何节点的两个子树的高度最大差别为一,所以它也被称为高度平衡树. 查找.插入和删除在平均和最坏情况下都是O(log n).增 ...
- 分布式进阶(九)Ubuntu下使用nsenter进入Docker容器
使用nsenter进入Docker容器 Docker容器运行后,如何进入容器进行操作呢?起初我是用SSH.如果只启动一个容器,用SSH还能应付,只需要将容器的22端口映射到本机的一个端口即可.当我启动 ...