spring的问题

Henry2010 2008-06-16 09:24:56
异常如下:
junit.framework.AssertionFailedError: Exception in constructor: testAddItem (org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemManager' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
....more

applicationContext.xml 中的dao 的配置如下:
<bean id="itemDaoHibernateImpl" class="net.shopping.Dao.impl.HibernateImpl.ItemDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

我的dao继承了BaseDao,BaseDao继承了HibernateDaoSupport,其它的DAO都没问题,只有这个。。。
搞不懂为什么!!
...全文
243 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
buybyetoo 2008-10-15
  • 打赏
  • 举报
回复
少了个 bean 应该是ref bean
Henry2010 2008-06-16
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 Landor2004 的回复:]
继续贴出程序代码瞧瞧,呵呵
[/Quote]

public class ItemServiceTest extends TestCase {
private ApplicationContext factory = new ClassPathXmlApplicationContext(
"applicationContext.xml");//错误
private itemService is = (itemService) factory.getBean("itemManager");
//错在上面以后的省略
}
Landor2004 2008-06-16
  • 打赏
  • 举报
回复
继续贴出程序代码瞧瞧,呵呵
Henry2010 2008-06-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yetaodiao 的回复:]
web.xml呢
[/Quote]

我实在junit中侧 service ,没启动web容器
Henry2010 2008-06-16
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Landor2004 的回复:]
检查你的ItemDaoHibernateImpl类是否真继承了你所说的BaseDao
[/Quote]

肯定继承了!所以才很奇怪!!
Landor2004 2008-06-16
  • 打赏
  • 举报
回复
检查你的ItemDaoHibernateImpl类是否真继承了你所说的BaseDao
  • 打赏
  • 举报
回复
web.xml呢
Henry2010 2008-06-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zhj92lxs 的回复:]
'sessionFactory' or 'hibernateTemplate' 这两个你配置好了吗
[/Quote]

好像不用,我是继承了HibernateDaoSupport,除了itemDao之外,其它的都侧过,没问题的
Henry2010 2008-06-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Landor2004 的回复:]
配置文件代码全贴出来吧
[/Quote]

<?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: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-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">


<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url"
value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="scott"></property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>net/shopping/entity/Product.hbm.xml</value>
<value>net/shopping/entity/ProductType.hbm.xml</value>
<value>net/shopping/entity/User.hbm.xml</value>
<value>net/shopping/entity/Address.hbm.xml</value>
<value>net/shopping/entity/Item.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<!-- 关闭 自动建表
<prop key="hibernate.hbm2ddl.auto">update</prop>
-->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>

<!-- 声明式事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- advice 设置事务属性 -->
<tx:advice id="transactionAdvice">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="update*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>

<!-- 应用事务到需要的类 -->
<aop:config>
<aop:advisor advice-ref="transactionAdvice" pointcut="execution(* service..*.*(..))"/>
</aop:config>

<!-- Dao 配置 -->
<bean id="productDaoHibernateImpl" class="net.shopping.Dao.impl.HibernateImpl.ProductDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="productTypeDaoHibernateImpl" class="net.shopping.Dao.impl.HibernateImpl.ProductTypeDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="userDaoHibernateImpl" class="net.shopping.Dao.impl.HibernateImpl.UserDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="addressDaoHibernateImpl" class="net.shopping.Dao.impl.HibernateImpl.AddressDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="itemDaoHibernateImpl" class="net.shopping.Dao.impl.HibernateImpl.ItemDaoHibernateImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<!-- Service 配置 -->
<bean id="productManager" class="net.shopping.service.impl.ProductServiceImpl">
<property name="productdao" ref="productDaoHibernateImpl"/>
</bean>

<bean id="productTypeManager" class="net.shopping.service.impl.ProductTypeServiceImpl">
<property name="productTypedao" ref="productTypeDaoHibernateImpl"/>
</bean>

<bean id="userManager" class="net.shopping.service.impl.UserServiceImpl">
<property name="userdao" ref="userDaoHibernateImpl"/>
</bean>

<bean id="addressManager" class="net.shopping.service.impl.AddressServiceImpl">
<property name="addressdao" ref="addressDaoHibernateImpl"/>
</bean>

<bean id="itemManager" class="net.shopping.service.impl.ItemServiceImpl">
<property name="itemdao" ref="itemDaoHibernateImpl"/>
</bean>
</beans>
zhj92lxs 2008-06-16
  • 打赏
  • 举报
回复
'sessionFactory' or 'hibernateTemplate' 这两个你配置好了吗
Landor2004 2008-06-16
  • 打赏
  • 举报
回复
配置文件代码全贴出来吧
Henry2010 2008-06-16
  • 打赏
  • 举报
回复
.......................

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧