java - Spring + Hibernate + Gradle-> org.springframework.beans.factory.BeanCreationException

标签 java spring hibernate gradle

我有一台开发PC,其中包含在apache-tomcat中运行的Web应用程序的代码。该代码使用spring和hibernate,为了生成.war,我需要使用“gradle”。

在此开发PC上生成此.war时,一切都很好,但是当我将所有代码复制到本地PC并生成此war时,启动Apache时会导致异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workflowController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.test2.section.mastertables.listboxes.service.ListboxService com.test.test2.section.workflow.controller.AbstractController.listboxService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'listboxService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.test.test2.section.mastertables.listboxes.service.ListboxCodeService com.test.test2.section.mastertables.listboxes.service.ListboxService.listboxCodeService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'listboxCodeService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: protected void com.test.test2.section.mastertables.listboxes.service.ListboxCodeService.setEntityDao(com.test.test2.section.generic.dao.GenericEntityDao); nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.test.test2.section.generic.dao.GenericEntityDao] is defined: expected single matching bean but found 37: commonDao,reinsuranceDao,serviceDao,masterServiceDao,poolDao,lookupCodeDao,lookupLangDao,listboxItemDao,listboxCodeDao,userDao,roleDao,contractDao,subContractDao,premiumsDao,selfRetentionDao,serviceContractDao,salarySumDao,logBookDao,productDao,technicalDataDao,reglementDao,cancellationDao,customerDao,mutableDao,messageSourceDao,populationDao,auditDao,reInsuranceSolutionDao,premiumSplitODao,pensionFundDao,documentDao,tariffBasicsDao,mySamEmployeeDao,mySamServiceDao,mySamContractDao,mySamPensionFundDao,mySamRevInfoDao ...



我解压缩了生成的两个jar,一个在dev PC中,一个在我的本地PC中,唯一的区别是在.class文件中,其余的是相同的:jars,.jsp ...我在两台PC中都使用相同的gradle版本和相同的gradle构建文件,相同的源代码,相同的Java版本。对于这个问题,您可以给我任何想法,我将不胜感激。

编辑:

因此,我可以反编译两次 war 中的类进行比较。怀疑这是结果:

来自工作 jar 的类:
@Service
public class ListboxCodeService extends GenericService
{

public ListboxCodeService()
{
}

@Autowired
protected void setEntityDao(ListboxCodeDao entityDao)
{
    this.entityDao = entityDao;
}

public ListboxCode getByCode(String code)
{
    return ((ListboxCodeDao)entityDao).getByCode(code);
}

protected volatile void setEntityDao(GenericEntityDao x0)
{
    setEntityDao((ListboxCodeDao)x0);
}

}

从不工作 war 中上课:
@Service
public class ListboxCodeService extends GenericService
{

public ListboxCodeService()
{
}

@Autowired
protected void setEntityDao(ListboxCodeDao entityDao)
{
    this.entityDao = entityDao;
}

public ListboxCode getByCode(String code)
{
    return ((ListboxCodeDao)entityDao).getByCode(code);
}

@Autowired
protected volatile void setEntityDao(GenericEntityDao genericentitydao)
{
    setEntityDao((ListboxCodeDao)genericentitydao);
}

}

区别在于非工作代码中额外的@Autowired。但是,初始的Java代码是:
@Service
public class ListboxCodeService extends GenericService<ListboxCode, ListboxCodeDao> {

@Autowired
@Override
protected void setEntityDao(ListboxCodeDao entityDao) {
    this.entityDao = entityDao;
}

/**
 * Gets the by code.
 *
 * @param code the code
 * @return the by code
 */
public ListboxCode getByCode(String code) {
    return entityDao.getByCode(code);
}

}

所以我现在的问题是,谁会添加这个额外的@Autowire?如我之前所说,它是相同的代码,相同的gradle版本和相同的java版本...知道吗?我们正计划将此DEV环境用于其他目的,并且必须确保可以在本地PC上生成有效版本。

最佳答案

所以我可以解决它。

我可以生成我的war文件,并且运行无异常。我之前曾说过我有相同的Java版本,但这不是真的。在DEV系统(我可以在其中产生右战)中,它是1.7.0_79_b2,而在我的本地PC中,我有1.7.0_80-b15。就是这样...我安装了1.7.0_79_b2,而 war 是通过.class生成的,其中不包含多余的@Autowire。我仍然感到震惊。

关于java - Spring + Hibernate + Gradle-> org.springframework.beans.factory.BeanCreationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41740407/

相关文章:

java - 从 byte[] 转换为 int 时得到错误的数字

java - InitBinder 未被调用/调用

java - 基本实体上的 Hibernate manyToOne 过滤器

hibernate - 指定 hibernate.jdbc.batch_size 有什么意义?

java - WHERE 子句和通配符中的变量值

java - 如何使用 Spring Boot 返回一组对象?

java - 在 Spring Boot 应用程序中防止自定义异常的堆栈跟踪日志记录

java - 复合主键是最好的解决方案 - Hibernate Spring

java - 当我与自定义 SWT 组件交互时它会闪烁

java - Mapstruct 可选映射