急!!!关于SSH2 spring对象注入问题..感觉很简单就是不知道哪错了.
今天做了一个关于SSH2得工程. tomcat启动没有报错.struts框架好使.但是当action类直接调用dao类就出错了.给人的感觉就是dao的对象没有注入进去...关于整合这块我是个菜鸟.找了2天了.希望高手来指点指点啊..
Spring XML代码
Action类代码
DAO 类 代码
然后是异常..类代码
Spring 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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:oracle9i">
</property>
<property name="username" value="cxc"></property>
<property name="password" value="cxc"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>cn/cxc/model/Userinfo.hbm.xml</value></list>
</property></bean>
<bean id="UserinfoDAO" class="cn.cxc.dao.UserinfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userinfoaction" class="cn.cxc.action.UserinfoAction">
<property name="userinfodao">
<ref bean="UserinfoDAO" />
</property>
</bean>
</beans>
Action类代码
package cn.cxc.action;
import javax.persistence.Entity;
import cn.cxc.dao.UserinfoDAO;
import cn.cxc.model.Userinfo;
@Entity
public class UserinfoAction {
private UserinfoDAO userinfodao;
public UserinfoDAO getUserinfodao() {
return userinfodao;
}
public void setUserinfodao(UserinfoDAO userinfodao) {
this.userinfodao = userinfodao;
}
public String test(){
userinfodao.sshtest();
System.out.println("测试struts");
return "success";
}
}
DAO 类 代码
package cn.cxc.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.cxc.model.Userinfo;
public class UserinfoDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(UserinfoDAO.class);
//property constants
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
public void sshtest(){
System.out.println("测试SSH2....");
}
以下忽略。。。
然后是异常..类代码
at cn.cxc.action.UserinfoAction.test(UserinfoAction.java:19)
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:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
以下忽略...
...全文
相关推荐
SSH框架搭建+struts零配置+spring自动注入 简单实例
该项目实现了SSH(Struts2、Spring、Hibernate)框架的集成,采用Struts零配置方式和Spring自动注入机制。通过web.xml配置核心过滤器,结合applicationCo
ssh 整合注入,教训,注入,为空
在IT行业中,SSH整合是指Spring、Struts2和Hibernate三个开源框架的集成,它们共同构建了一个强大的企业级应用开发框架。
特殊情况(ActionForm,Servlet, Filter, Listener)下Spring如何注入对象
在Spring框架中,如果需要在ActionForm中注入其他对象,例如数据库访问层的服务,可能会遇到问题,因为ActionForm通常是非Spring管理的bean。
基于SSH(STRUTS2 Spring Hibernate)的网上购物系统
2. **Spring**:Spring是一个全面的后端开发框架,提供了依赖注入(DI)和面向切面编程(AOP)等核心功能。
在SSH框架Spring的作用
这种模式不仅降低了组件间的耦合,还使得单元测试变得更为简单,因为可以轻松地替换依赖项为模拟对象。


Web 开发
