1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xmlns:aop="http://www.springframework.org/schema/aop" 7 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd 9 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 10 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> 11 12 13 14 15 16 17 18 <!-- sessionfactory配置 --> 19 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 20 <property name="configLocation"> 21 <value>classpath:hibernate.cfg.xml</value> 22 </property> 23 </bean> 24 25 <!-- txManager配置 --> 26 <bean id="txManage" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 27 <property name="sessionFactory" ref="sessionFactory"></property> 28 </bean> 29 30 <!-- 定义事务通知 --> 31 <tx:advice id="txAdvice" transaction-manager="txManage"> 32 <tx:attributes> 33 <tx:method name="*" propagation="REQUIRED"/> 34 </tx:attributes> 35 </tx:advice> 36 37 <aop:config> 38 <aop:pointcut expression="execution(* com.ywt.service..*.*(..))" id="serverMethod"/> 39 <aop:advisor advice-ref="txAdvice" pointcut-ref="serverMethod"/> 40 </aop:config> 41 42 <!-- 实体bean --> 43 <bean id="detailbean" class="com.ywt.bean.Bug_detail"></bean> 44 <bean id="projectbean" class="com.ywt.bean.Bug_project"></bean> 45 46 47 <!-- dao层 --> 48 <bean id="detailDaoImpl" class="com.ywt.dao.impl.Bug_detailDaoImpl"> 49 <property name="sessionFactory" ref="sessionFactory"></property> 50 </bean> 51 <bean id="projectDaoImpl" class="com.ywt.dao.impl.Bug_projectDaoImpl"> 52 <property name="sessionFactory" ref="sessionFactory"></property> 53 </bean> 54 55 <!-- service层 --> 56 <bean id="detailServiceDaoimpl" class="com.ywt.service.impl.Bug_detailServiceImpl"> 57 <property name="detailDao" ref="detailDaoImpl"></property> 58 </bean> 59 <bean id="projectServiceDaoimpl" class="com.ywt.service.impl.Bug_projectServiceImpl"> 60 <property name="projectDao" ref="projectDaoImpl"></property> 61 </bean> 62 63 64 <!-- ActionBean --> 65 <bean id="bug_detailAction" class="com.ywt.web.action.Bug_detailAction" scope="prototype"> 66 <property name="bug_detailService" ref="detailServiceDaoimpl"></property> 67 <property name="bug_projectService" ref="projectServiceDaoimpl"></property> 68 </bean> 69 70 71 72 </beans>
package com.ywt.service.impl; import java.util.List; import com.ywt.bean.Bug_project; import com.ywt.dao.Bug_projectDao; import com.ywt.dao.impl.Bug_projectDaoImpl; import com.ywt.service.Bug_projectService; public class Bug_projectServiceImpl implements Bug_projectService { private Bug_projectDao projectDao ; public List<Bug_project> getProject() { return projectDao.getProject(); } public Bug_projectDao getProjectDao() { return projectDao; } public void setProjectDao(Bug_projectDao projectDao) { this.projectDao = projectDao; } }
package com.ywt.service.impl; import java.util.List; import com.ywt.bean.Bug_detail; import com.ywt.dao.Bug_detailDao; import com.ywt.service.Bug_detailService; public class Bug_detailServiceImpl implements Bug_detailService { private Bug_detailDao detailDao; public List<Bug_detail> getAll() { return detailDao.getAll(); } public List<Bug_detail> getProjectBug(Integer pid) { return detailDao.getProjectBug(pid); } public boolean addBug(Bug_detail detail) { return detailDao.addBug(detail); } public Bug_detailDao getDetailDao() { return detailDao; } public void setDetailDao(Bug_detailDao detailDao) { this.detailDao = detailDao; } }
package com.ywt.dao.impl; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.ywt.bean.Bug_project; import com.ywt.dao.Bug_projectDao; public class Bug_projectDaoImpl extends HibernateDaoSupport implements Bug_projectDao { public List<Bug_project> getProject() { Session session = null; try { String hql = "from Bug_project"; session = this.getSessionFactory().openSession(); Query query = session.createQuery(hql); return query.list(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ session.close(); } return null; } }
package com.ywt.dao.impl; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import com.ywt.bean.Bug_detail; import com.ywt.dao.Bug_detailDao; public class Bug_detailDaoImpl extends HibernateDaoSupport implements Bug_detailDao { @SuppressWarnings("unchecked") public List<Bug_detail> getAll() { Session session = null; try { String hql = "from Bug_detail"; session = this.getSessionFactory().openSession(); Query query = session.createQuery(hql); return query.list(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ session.close(); } return null; } @SuppressWarnings("unchecked") public List<Bug_detail> getProjectBug(Integer pid) { Session session = null; try { String hql = "from Bug_detail as b where b.p_id = ?"; session = this.getSessionFactory().openSession(); Query query = session.createQuery(hql); query.setInteger(0, pid); return query.list(); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ session.close(); } return null; } public boolean addBug(Bug_detail detail) { boolean flg = true; Session session = null; try { session = this.getSessionFactory().openSession(); session.beginTransaction().begin(); session.save(detail); } catch (HibernateException e) { // TODO Auto-generated catch block e.printStackTrace(); session.beginTransaction().rollback(); flg = false; }finally{ session.beginTransaction().commit(); session.close(); } return flg; } }
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <!-- 配置struts2的上下文清除过滤器它会在doFilter方法里设置一个计数器counter的初始值为1,有了这个值,后续的核心过滤器 就不会清空ActionContext,而是由之前的过滤器也就是ActionContextCleanUp来清空ActionContext --> <filter> <filter-name>struts2ContextCleanUp</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter-mapping> <filter-name>struts2ContextCleanUp</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 配置struts2的核心控制器 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Spring配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
14:23:47,796 WARN OgnlValueStack:45 - Could not find property [struts.actionMapping] 14:23:47,890 WARN OgnlValueStack:45 - Could not find property [struts.valueStack] java.lang.NullPointerException at com.ywt.web.action.Bug_detailAction.getBUGAll(Bug_detailAction.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) 14:23:48,734 WARN OgnlValueStack:45 - Could not find property [org.apache.catalina.jsp_file]
at com.ywt.web.action.Bug_detailAction.getBUGAll(Bug_detailAction.java:20)
你贴了这么多代码 怎么没贴Action的代码 和配置
感觉你的调用转向写的有问题,试试这样写.
<bean id="你的请求action" class="所要转向的action类" scope="prototype"> <property name="service"> <bean class="com.ywt.service.impl.Bug_detailServiceImpl"> <property name="dao"> <bean class="com.ywt.dao.impl.Bug_detailDaoImpl">
</bean>
</property>
</bean>
</property>
</bean>