报错信息:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ymUserQqDaoImpl' defined in class path resource [spring-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.yanmad.data.dao.impl.YmUserQqDaoImpl]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:802)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:583)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1068)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
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 org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.yanmad.data.dao.impl.YmUserQqDaoImpl]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
... 37 more
Caused by: java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.util.Assert.notNull(Assert.java:123)
at com.yanmad.data.dao.impl.BaseHibernateDao.<init>(BaseHibernateDao.java:50)
at com.yanmad.data.dao.impl.YmUserQqDaoImpl.<init>(YmUserQqDaoImpl.java:12)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 39 more
<!-- 把C3P0数据源注入给Session工厂 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 配置映射文件 -->
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 把Session工厂注入给hibernateTemplate -->
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<constructor-arg>
<ref local="sessionFactory" />
</constructor-arg>
</bean>
<!-- 1.把DAO注入给Session工厂 -->
<!-- 2.把Service注入给DAO -->
<!-- 3.把Action注入给Service -->
<bean id ="ymUserQqDaoImpl" class="com.yanmad.data.dao.impl.YmUserQqDaoImpl" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="ymOtherLoginServiceImpl" class="com.yanmad.xm.service.impl.YmOtherLoginServiceImpl">
<property name="ymUserQqDaoImpl" ref="ymUserQqDaoImpl"></property>
</bean>
<bean id="testAction" class="com.yanmad.xm.action.TestAction" scope="prototype">
<property name="ymOtherLoginServiceImpl" ref="ymOtherLoginServiceImpl"></property>
</bean>
YmUserQqDaoImpl :
public class YmUserQqDaoImpl extends BaseHibernateDao<YmUserQq,Long> implements YmUserQqDao {
private SessionFactory sessionFactory;
private YmUserQqDao ymUserQqDao;
public void setYmUserQqDao(YmUserQqDao ymUserQqDao) {
this.ymUserQqDao = ymUserQqDao;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
}
YmOtherLoginServiceImpl :
public class YmOtherLoginServiceImpl implements YmOtherLoginService{
private YmUserQqDao ymUserQqDao;
private YmUserWeiboDao ymUserWeiboDao;
private YmUserWeixinDao ymUserWeixinDao;
public void setYmUserQqDao(YmUserQqDao ymUserQqDao) {
this.ymUserQqDao = ymUserQqDao;
}
public void setYmUserWeiboDao(YmUserWeiboDao ymUserWeiboDao) {
this.ymUserWeiboDao = ymUserWeiboDao;
}
public void setYmUserWeixinDao(YmUserWeixinDao ymUserWeixinDao) {
this.ymUserWeixinDao = ymUserWeixinDao;
}
public YmUserQq findQqUid(String qqUserId) {
qqUserId = "10000";
return ymUserQqDao.uniqueSelf("from YmUserQq as q where q.qq_user_id = ?",qqUserId);
}
public YmUserWeibo findWbUid(String weiboUserId) {
return ymUserWeiboDao.uniqueSelf("from YmUserQq as w where w.wb_user_id = ?", weiboUserId);
}
public YmUserWeixin findWxUid(String weixinUserId) {
return ymUserWeixinDao.uniqueSelf("from YmUserQq as x where x.wx_user_id = ?", weixinUserId);
}
}
搞好多天了都没弄好,各位前辈给看看吧,不是太懂 谢谢了!!
------解决思路----------------------
Constructor threw exception; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
是不是因为
<bean id ="ymUserQqDaoImpl" class="com.yanmad.data.dao.impl.YmUserQqDaoImpl" >
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>只注入了一个属性!
而
private SessionFactory sessionFactory;
private YmUserQqDao ymUserQqDao;
存在两个属性!
------解决思路----------------------
楼上讲的不错,搞不懂为什么要这个属性private YmUserQqDao ymUserQqDao;
要不去掉setYmUserQqDao方法试试
------解决思路----------------------
异常信息很明显了啊:
Caused by: java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.util.Assert.notNull(Assert.java:123)
at com.yanmad.data.dao.impl.BaseHibernateDao.<init>(BaseHibernateDao.java:50)
at com.yanmad.data.dao.impl.YmUserQqDaoImpl.<init>(YmUserQqDaoImpl.java:12)
BaseHibernateDao.java:50的代码是什么!