Spring.xml的代码: <bean id="getProductAction" class="action.getProductAction">
<property name="productBiz">
<ref bean="ProductBiz"/>
</property>
</bean>
<bean id="productAction" class="action.productAction">
<property name="productBiz">
<ref bean="ProductBiz"/>
</property>
</bean>Action里的代码: private IProductBiz productBiz = null;
private int id;
public String execute() throws Exception {
Product product = new Product();
product = productBiz.findById(id);
Map session = ActionContext.getContext().getSession();
session.put("product", product);
return SUCCESS;
} public void setProductBiz(IProductBiz productBiz) {
this.productBiz = productBiz;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
}
private IProductBiz productBiz = null;
public String execute() throws Exception {
List<Product> newList = new ArrayList<Product>();
newList = productBiz.findByTime();
Map session = ActionContext.getContext().getSession();
session.put("newProducts", newList);
List<Product> pList = new ArrayList<Product>();
pList = productBiz.findAll();
session.put("products", pList);
return SUCCESS;
}
public void setProductBiz(IProductBiz productBiz) {
this.productBiz = productBiz;
}
问题是getProduct的Action里面的productBiz能实例化~但是到了product的Action里面的productBiz却为空~~以前做别的Spring里面两个同样的依赖注入都没有问题~但是现在做这个不知道为什么~Spring里面两个同样的注入就只有第一个能实例化.后面加入的都是为空~调试时候setter里面获取到接口的实例化但是到了方法运行又为空了~求高手解决~新手坐等~
<property name="productBiz">
<ref bean="ProductBiz"/>
</property>
</bean>
<bean id="productAction" class="action.productAction">
<property name="productBiz">
<ref bean="ProductBiz"/>
</property>
</bean>Action里的代码: private IProductBiz productBiz = null;
private int id;
public String execute() throws Exception {
Product product = new Product();
product = productBiz.findById(id);
Map session = ActionContext.getContext().getSession();
session.put("product", product);
return SUCCESS;
} public void setProductBiz(IProductBiz productBiz) {
this.productBiz = productBiz;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
}
private IProductBiz productBiz = null;
public String execute() throws Exception {
List<Product> newList = new ArrayList<Product>();
newList = productBiz.findByTime();
Map session = ActionContext.getContext().getSession();
session.put("newProducts", newList);
List<Product> pList = new ArrayList<Product>();
pList = productBiz.findAll();
session.put("products", pList);
return SUCCESS;
}
public void setProductBiz(IProductBiz productBiz) {
this.productBiz = productBiz;
}
问题是getProduct的Action里面的productBiz能实例化~但是到了product的Action里面的productBiz却为空~~以前做别的Spring里面两个同样的依赖注入都没有问题~但是现在做这个不知道为什么~Spring里面两个同样的注入就只有第一个能实例化.后面加入的都是为空~调试时候setter里面获取到接口的实例化但是到了方法运行又为空了~求高手解决~新手坐等~
解决方案 »
- firefox下 判断用户名为空的问题
- java树形菜单的,简单的哈
- 请教jsp中下拉列表的动态查询
- java MSSQL错误。。十万火急
- 问一个关于在JSP中对从数据库中的数据排序的问题
- JAVA中怎样将UTF-8转换成GB2312
- ***请教,request.getAttributeNames()的用法,在线等!!!***
- 求助!!session过期问题??
- 关于在function里边调用jsp页面已有的list集合的问题
- sql语句无效列类型,请教问题在哪?
- 怎样能快速看懂代码,分析出用到的数据库表和里面的字段?
- 求高手。。could not open hibernate session..(偶尔出现)
你没有定义过这样一个bean 怎么能ref
你的这个bean有没有定义过啊?把全部的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"
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-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.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:orcl">
</property>
<property name="username" value="easy"></property>
<property name="password" value="easy"></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>entity/Product.hbm.xml</value>
<value>entity/Maintype.hbm.xml</value>
<value>entity/Idea.hbm.xml</value>
<value>entity/Detail.hbm.xml</value>
<value>entity/Customer.hbm.xml</value>
<value>entity/Notice.hbm.xml</value>
<value>entity/Admin.hbm.xml</value>
<value>entity/Sontype.hbm.xml</value>
<value>entity/Payment.hbm.xml</value>
<value>entity/Orders.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置hibernate的事务管理器 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 通过<td:advice>标签指定事务管理器 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 定义属性,声明事务规则 -->
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="drop*" propagation="REQUIRED" />
<tx:method name="do*" propagation="REQUIRED" />
<tx:method name="merge*" propagation="REQUIRED" />
<tx:method name="regi*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" propagation="REQUIRED" />
</tx:attributes>
</tx:advice> <aop:config>
<!-- 定义哪些方法应用这些规则 -->
<aop:pointcut id="daoMethod" expression="execution(* dao.*.*(..))" />
<!-- 将事务通知与应用规则的方法组合 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethod" />
</aop:config>
<bean id="ProductDAO" class="dao.impl.ProductDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="MaintypeDAO" class="dao.impl.MaintypeDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="IdeaDAO" class="dao.impl.IdeaDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="DetailDAO" class="dao.impl.DetailDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="CustomerDAO" class="dao.impl.CustomerDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="NoticeDAO" class="dao.impl.NoticeDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="AdminDAO" class="dao.impl.AdminDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="SontypeDAO" class="dao.impl.SontypeDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PaymentDAO" class="dao.impl.PaymentDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="OrdersDAO" class="dao.impl.OrdersDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 将dao注入到biz -->
<bean id="AdminBiz" class="biz.impl.AdminBizImpl">
<property name="adminDao">
<ref bean="AdminDAO" />
</property>
</bean>
<bean id="CustonmerBiz" class="biz.impl.CustomerBizImpl">
<property name="customerDao">
<ref bean="CustomerDAO" />
</property>
</bean>
<bean id="DetailBiz" class="biz.impl.DetailBizImpl">
<property name="detailDao">
<ref bean="DetailDAO" />
</property>
</bean>
<bean id="IdeaBiz" class="biz.impl.IdeaBizImpl">
<property name="ideaDao">
<ref bean="IdeaDAO" />
</property>
</bean>
<bean id="MainTypeBiz" class="biz.impl.MainTypeBizImpl">
<property name="mainTypeDao">
<ref bean="MaintypeDAO" />
</property>
</bean>
<bean id="NoticeBiz" class="biz.impl.NoticeBizImpl">
<property name="noticeDao">
<ref bean="NoticeDAO" />
</property>
</bean>
<bean id="OrdersBiz" class="biz.impl.OrdersBizImpl">
<property name="ordersDao">
<ref bean="OrdersDAO" />
</property>
</bean>
<bean id="PaymentBiz" class="biz.impl.PaymentBizImpl">
<property name="paymentDao">
<ref bean="PaymentDAO" />
</property>
</bean>
<bean id="ProductBiz" class="biz.impl.ProductBizImpl">
<property name="productDao">
<ref bean="ProductDAO" />
</property>
</bean>
<bean id="SontypeBiz" class="biz.impl.SontypeBizImpl">
<property name="sontypeDao">
<ref bean="SontypeDAO" />
</property>
</bean> <import resource="app_pyy.xml" />
<import resource="app_czh.xml" />
</beans>
不是我bean里面的没有定义过~是有定义了~~因为第一个都能实例化但是后面的都不行了