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的更多相关文章

  1. springboot+maven整合spring security

    springboot+maven整合spring security已经做了两次了,然而还是不太熟悉,这里针对后台简单记录一下需要做哪些事情,具体的步骤怎么操作网上都有,不再赘述.1.pom.xml中添 ...

  2. Maven 整合 spring profile实现多环境自动切换

    Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...

  3. eclipse环境下基于已构建struts2项目整合spring+hibernate

    本文是基于已构建的struts2项目基础上整合 spring+hibernate,若读者还不熟悉struts2项目,请先阅读 eclipse环境下基于tomcat-7.0.82构建struts2项目 ...

  4. 使用maven整合spring+springmvc+mybatis

    使用maven整合spring+springmvc+mybatis 开发环境: 1. jdk1.8 2. eclipse4.7.0 (Oxygen) 3. mysql 5.7 在pom.xml文件中, ...

  5. Maven整合Spring与Solr

    首先,在maven的pom.xml文件中配置对spring和solrj客户端的依赖: <project xmlns="http://maven.apache.org/POM/4.0.0 ...

  6. 借助Maven入手Spring Boot第一个程序

    目前网上有不少Spring Boot的入门文章,都很有帮助,本人最近在深入学习Spring Cloud,在搭建第一个Hello World程序时,感觉对于新手而言,介绍文章怎么详细都不为过,因为其中坑 ...

  7. jersey2 整合 spring + hibernate + log4j2

    整合 spring jersey2 官方还未正式支持 spring4, 但网上有好多支持方案,折腾了一圈后,还是用了 spring3; pom 添加以下依赖配置 <!-- Spring --&g ...

  8. maven学习记录三——maven整合ssh框架

    6       整合ssh框架 6.1     依赖传递 只添加了一个struts2-core依赖,发现项目中出现了很多jar, 这种情况 叫 依赖传递 6.2     依赖版本冲突的解决 1.  第 ...

  9. Maven配置Spring+Hibernate Shiro权限控制项目

    前言:在Eclipse中安装好Maven插件,然后创建一个Sample项目.在Eclipse中检出Shiro的官方演示样例.地址http://svn.apache.org/repos/asf/shir ...

随机推荐

  1. JVM常量池和八种基本数据及字符串

    迄今为止看到的对常量池和字符串最为透彻的解释,赞一个! 常量池(constant_pool)指的是在编译期被确定,并被保存在已编译的.class文件中的一些数据.它包括了关于类.方法.接口等中的常量, ...

  2. 控制成本,控制成本知识点,挣值和实际成本、EAC,ETC.TCPI解析表

  3. Android View架构总结

    View和Activity的区别 android的四大组件,Activity是四大组件中唯一一个用来和用户进行交互的组件.可以说Activity就是android的视图层. 如果再细化,Activit ...

  4. JS 可变参数

     JS可变参数的方法不需要参数,同时,我们应该注意在写JS文件的时候避免定义arguments变量. <html> <head> <title>Javascri ...

  5. iOS中 快速正确的安装 CocoaPods

    有问题或技术交流可以咨询!欢迎加入! 第一部分: CocoaPods 的安装 步骤1 - 安装 RVM RVM 是干什么的这里就不解释了,后面你将会慢慢搞明白. $ curl -L https://g ...

  6. CUDA command Profiler

    这里我不使用默认设置: timestamp gpustarttimestamp gpuendtimestamp gridsize threadblocksize dynsmemperblock sta ...

  7. Bias and Variance 偏置和方差

    偏置和方差 参考资料:http://scott.fortmann-roe.com/docs/BiasVariance.html http://www.cnblogs.com/kemaswill/ Bi ...

  8. Spring mvc,uploadifive 文件上传实践(转自:https://segmentfault.com/a/1190000004503262)

     1.前台页面: 引入js和css 全选复制放进笔记 <link type="text/css" rel="stylesheet" href=&quo ...

  9. HTML5 预加载

    原文地址: HTML5 Link Prefetching 原文日期: 2010年07月07日 翻译日期: 2013年08月13日 浏览器厂商和开发者之间共同努力的一个方向就是让网站更快.现在已有很多广 ...

  10. Adapterview和adapter的联系

    在J2EE中提供过一种非常好的框架--MVC框架,实现原理:数据模型M(Model)存放数据,利用控制器C(Controller)将数据显示在视图V(View)上.在Android中有这样一种高级控件 ...