记录一下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 ...
随机推荐
- 一步步创建Qt Widget项目+TextFinder案例(摘自笔者2015年将出的《QT5权威指南》,本文为试读篇)
创建一个基于应用的QtWidget应用程序 这个手册描述了怎样使用QtCreater创建个一个小的Qt应用程序,Text Finder.它是Qt工具Text Finder例子的简写版本.这个应用 ...
- Quick-Cocos2d-X 捋一捋框架流程
猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/?p=535 一直比较关注Quick L ...
- SSH深度历险(六) 深入浅出----- Spring事务配置的五种方式
这对时间在学习SSH中Spring架构,Spring的事务配置做了详细总结,在此之间对Spring的事务配置只是停留在听说的阶段,总结一下,整体把控,通过这次的学习发觉Spring的事务配置只要把思路 ...
- Android简易实战教程--第五话《开发一键锁屏应用》
转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/51860900 点击打开链接 Device Administration 对于这个应 ...
- Cocos2D iOS之旅:如何写一个敲地鼠游戏(二):Cocos2D中的高清支持
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...
- Hessian源码分析--HessianServlet
Hessian可以通过Servlet来对外暴露服务,HessianServlet继承于HttpServlet,但这仅仅是一个外壳,使用web服务器来提供对外的Http请求,在web.xml中我们会进行 ...
- 用SpriteBuilder简化"耕牛遍地走"的动画效果(四)
写到这突然有童鞋质疑,你这哪里是牛,分明是熊嘛! 仔细看了下,还真像牛.反正是这个意思.怪本猫猪牛熊不分,好在道理是一样的. 下面继续,言归正传. 添加一个空白的touchBegan方法,如果没有这个 ...
- python multiprocessing example
python multiprocessing example Server Code: #!/usr/bin/python #-*- coding: UTF-8 -*- # mpserver.py # ...
- SQL Server扫盲系列——镜像篇
为方便查看,并以专题形式展示,所以我会把一些文章整合起来.本部分为SQL Server镜像系列: 本文出处:http://blog.csdn.net/dba_huangzj/article/detai ...
- android studio2.0出现的gradle问题,instant Run即时运行不了.
android studio 2.0出现的gradle问题: instant Run即时运行不了.经历了几乎9个preView版本的AS2.0,终于迎来了正式版,然而晴天我的霹雳,好不容易装好的2.0 ...