当前位置:编程学习 > JAVA >>

Spring构造函数注入,异常。求解决


log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.scpii.auto.易做图yze.FileOperator.main(FileOperator.java:56)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'basicBrandinfoDao' defined in file [E:\MyEclipse Workstation\AutoXmlAnalyze\bin\applicationContext.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for 易做图 parameters to avoid type ambiguities)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
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:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.scpii.auto.util.SpringBeanFactory.<clinit>(SpringBeanFactory.java:9)
... 1 more



相关的配置文件如下:

<?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-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">
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"></property>
<property name="url"
value="jdbc:oracle:thin:@218.6.170.246:1521:incubatordb">
</property>
<property name="username" value="admin"></property>
<property name="password" value="Buildapp123"></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>
com/scpii/auto/dao/xml/TbBasicCarinfo.hbm.xml
</value>
<value>
com/scpii/auto/dao/xml/TbBasicCarmain.hbm.xml
</value>
<value>
com/scpii/auto/dao/xml/TbBasicCarConfigParam.hbm.xml
</value>
<value>
com/scpii/auto/dao/xml/TbBasicCarconfig.hbm.xml
</value>
<value>
com/scpii/auto/dao/xml/TbBasicCarimg.hbm.xml
</value>
<value>
com/scpii/auto/dao/xml/TbBasicCarstyle.hbm.xml
</value>
<value>
com/scpii/auto/dao/xml/TbBasicBrandinfo.hbm.xml
</value>
</list>
</property>
</bean>

<!-- 构建事务 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<aop:pointcut id="transPointCut"
expression="execution(* com.scpii.auto.dao.*.*(..))" />
<aop:advisor advice-ref="transAdvice" pointcut-ref="transPointCut" />
</aop:config>
<tx:advice id="transAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="delete" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 实体Bean -->
<bean id="TbBasicBrandinfoBean" class="com.scpii.auto.entity.TbBasicBrandinfo" />
<bean id="TbBasicCarconfigBean" class="com.scpii.auto.entity.TbBasicCarconfig" />
<bean id="TbBasicCarConfigParamBean" class="com.scpii.auto.entity.TbBasicCarConfigParam" />
<bean id="TbBasicCarimgBean" class="com.scpii.auto.entity.TbBasicCarimg" />
<bean id="TbBasicCarinfoBean" class="com.scpii.auto.entity.TbBasicCarinfo" />
<bean id="TbBasicCarmainBean" class="com.scpii.auto.entity.TbBasicCarmain" />
<bean id="TbBasicCarstyleBean" class="com.scpii.auto.entity.TbBasicCarstyle" />

<!-- 注入BaseDao -->
<bean id="basicBrandinfoDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicBrandinfoBean" />
</bean>
<bean id="basicCarconfigDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicCarconfigBean" />
</bean>
<bean id="basicCarConfigParamDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicCarConfigParamBean" />
</bean>
<bean id="basicCarimgDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicCarimgBean" />
</bean>
<bean id="basicCarinfoDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicCarinfoBean" />
</bean>
<bean id="basicCarmainDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicCarmainBean" />
</bean>
<bean id="basicCarstyleDao" class="com.scpii.auto.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
<constructor-arg ref="TbBasicCarstyleBean" />
</bean>
<!-- Service -->
<bean id="basicBrandinfoService" class="com.scpii.auto.service.TbBasicBrandinfoService">
<property name="basicBrandInfoDao" ref="basicBrandinfoDao" />
</bean>
<bean id="basicCarConfigParamService" class="com.scpii.auto.service.TbBasicCarConfigParamService">
<property name="basicCarConfigParamDao" ref="basicCarConfigParamDao" />
</bean>
<bean id="basicCarconfigService" class="com.scpii.auto.service.TbBasicCarconfigService">
<property name="basicCarconfigDao" ref="basicCarconfigDao" />
</bean>
<bean id="basicCarimgService" class="com.scpii.auto.service.TbBasicCarimgService">
<property name="basicCarimgDao" ref="basicCarimgDao" />
</bean>
<bean id="basicCarinfoService" class="com.scpii.auto.service.TbBasicCarinfoService">
<property name="basicCarinfoDao" ref="basicCarinfoDao" />
</bean>
<bean id="basicCarmainService" class="com.scpii.auto.service.TbBasicCarmainService">
<property name="basicCarmainDao" ref="basicCarmainDao" />
</bean>
<bean id="basicCarstyleService" class="com.scpii.auto.service.TbBasicCarstyleService">
<property name="basicCarstyleDao" ref="basicCarstyleDao" />
</bean>

<!-- 注入XML解析类 -->
<bean id="xmlAnalyzeBean" class="com.scpii.auto.易做图yze.XmlAnalyze">
<property name="tbBasicBrandinfoService" ref="basicBrandinfoService" />
<property name="tbBasicCarConfigParamService" ref="basicCarConfigParamService" />
<property name="tbBasicCarconfigService" ref="basicCarconfigService" />
<property name="tbBasicCarimgService" ref="basicCarimgService" />
<property name="tbBasicCarinfoService" ref="basicCarinfoService" />
<property name="tbBasicCarmainService" ref="basicCarmainService" />
<property name="tbBasicCarstyleService" ref="basicCarstyleService" />
</bean>

<bean id="fileOperator" class="com.scpii.auto.易做图yze.FileOperator">
<property name="xmlAnalyze" ref="xmlAnalyzeBean"/>
</bean>
</beans>

--------------------编程问答--------------------
部分代码:

/**
 * 
 */
package com.scpii.auto.dao;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * UniversalApi
 * 
 * @author 甘建新 2012-7-15下午11:22:03
 * @param <T>
 */
public class BaseDao<T> extends HibernateDaoSupport implements BaseInte易做图ce<T> {
private Class<T> entity;

public BaseDao() {

}

public BaseDao(Class<T> entity) {
this.entity = entity;
}

public T get(Integer id) {
return (T) this.getHibernateTemplate().get(entity, id);
}

public T load(Integer id) {
return null;
}

public List<T> getAll() {
return this.getHibernateTemplate().loadAll(entity);
}

public T get(String propertyName, Object value) {
return null;
}

public List<T> getList(String propertyName, Object value) {
return null;
}

public Long getTotalCount() {
return null;
}

public void save(T obj) {
this.getHibernateTemplate().save(obj);
}

public void update(T obj) {
this.getHibernateTemplate().update(obj);
}

public void delete(T obj) {
this.getHibernateTemplate().delete(obj);
}

public void delete(Integer id) {
T t = this.get(id);
delete(t);
}

public List<T> hqlGetList(String hql, Map<String, Object> argsMap) {
if (hql!=null) {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Query query = session.getNamedQuery(hql);
if (argsMap!=null) {
Set set = argsMap.entrySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Map.Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
query.setParameter(entry.getKey(), entry.getValue());
}
}
return query.list();
}
return null;
}

public void hqlUpdate(String namedHqlQuery, Map<String, Object> argsMap) {
if (namedHqlQuery!=null) {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Query query = session.getNamedQuery(namedHqlQuery);
if (argsMap!=null) {
Set set = argsMap.entrySet();
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
query.setParameter(entry.getKey(), entry.getValue());
}
}
int i = query.executeUpdate();
logger.info("执行结果为"+i);
}
}

public Long hqlGetNums(String namedHqlQuery, Map<String, Object> argsMap) {
if (namedHqlQuery!=null && namedHqlQuery.trim().length()>0) {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Query query = session.getNamedQuery(namedHqlQuery);
if (argsMap!=null) {
Set set = argsMap.entrySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Map.Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
query.setParameter(entry.getKey(), entry.getValue());
}
}
List<T> tList = query.list();
if (tList!=null && tList.size()==1) {
return (Long) tList.get(0);
}
}
return (long) 0;
}

public List<T> sqlGetList(String sqls, Map<String, Object> argsMap) {
if (sqls!=null && sqls.trim().length()>0) {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Query query = session.createSQLQuery(sqls).addEntity(entity);
if (argsMap!=null) {
Set set = argsMap.entrySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Map.Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
query.setParameter(entry.getKey(), entry.getValue());
}
}
return query.list();
}
return null;
}

public void sqlUpdate(String sqls, Map<String, Object> argsMap) {
if (sqls!=null && sqls.trim().length()>0) {
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Query query = session.createSQLQuery(sqls).addEntity(entity);
// Query query = session.getNamedQuery(sqls);
if (argsMap!=null) {
Set set = argsMap.entrySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()){
Map.Entry<String, Object> entry = (Entry<String, Object>) iterator.next();
query.setParameter(entry.getKey(), entry.getValue());
}
}
int i = query.executeUpdate();
logger.info("执行结果为"+i);
}
}

public Long sqlGetNum(String sqls, Map<String, Object> argsMap) {
return null;
}

public Integer getNextId() throws Exception {
return null;
}
}

--------------------编程问答-------------------- "Please initialize the log4j system properly."   你加了log4j的包了吗? log4j.properties文件配置正确了吗? --------------------编程问答-------------------- 我虽是新手,不会解答问题,但我也看出问题不是log4j的,那只是两个警告而已,真正的异常是从第三句开始的。 --------------------编程问答-------------------- 检查一下的你的java代码得到'basicBrandinfoDao' 这个的时候,路径是否有误,E:\MyEclipse Workstation\AutoXmlAnalyze\bin\applicationContext.xml的配置路径都正确么?还有就是修改了xml文件后,要重启服务。 --------------------编程问答-------------------- 把 <bean id="TbBasicBrandinfoBean" class="com.scpii.auto.entity.TbBasicBrandinfo" />中的id 值首字母修改为小写:tbBasicBrandinfoBean,如果这种不行的话

   <constructor-arg >
       <bean class="com.scpii.auto.entity.TbBasicBrandinfo"/>
   </constructor-arg>

补充:Java ,  Java EE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,