【问题标题】:Spring 4.2.4 - Autowire stopped working in RAD WAS 8.5 once Java 8 was installedSpring 4.2.4 - 安装 Java 8 后,Autowire 在 RAD WAS 8.5 中停止工作
【发布时间】:2021-08-07 07:04:13
【问题描述】:

应用程序在 WAS 8.5 中运行良好几年,包括 RAD 中的本地 WAS8.5 服务器。在笔记本电脑上安装 Java 8,在 JDK 1.7 下的 RAD 中重新编译代码(仅在安装时),重新启动服务器并在启动时出现以下错误:

引起:org.springframework.beans.factory.BeanCreationException: 创建名为“addressController”的 bean 时出错:注入 自动装配依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 自动装配字段:私有 com.components.mds.service.StaticReferenceService com.mds.ui.controller.MDSBaseController.staticRefService; 嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 符合条件的 bean 类型 [com.components.mds.service.StaticReferenceService] 找到 对于依赖项:预计至少有 1 个符合自动装配条件的 bean 这种依赖的候选人。依赖注解: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 在 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

该应用程序具有带有演示文稿(jsps、控制器等)的 ear 和带有服务、DAO 等的 jar。jar 包含在 ear 的 lib 文件夹中。在耳朵(战争)中,控制器有如下代码:

@Controller

@SessionAttributes({MDS_PRESCRIBER_ADDRESS_MAP , MDS_PRESCRIBER}) 公共类地址控制器扩展 MDSBaseController {

private String editAddressID;
private AddressModel addressPhoneModel = new AddressModel();
@Autowired
AddressValidations addressValidator;

并且有 spring-context.xml 如下:

<context:spring-configured />
    <context:component-scan base-package="com.caremark.mds.ui.customtag"></context:component-scan>
    <context:load-time-weaver aspectj-weaving="on" />

上面将尝试自动装配 jar 中的类:

@Component

公共类地址验证器 {

public boolean validatePrescriberAddress(Address address){

... }

使用 spring-component-context.xml 指定 beans:

<!-- Bean defined in JAR -->
    <context:component-scan base-package=" com.components.mds.service" />
    <context:component-scan base-package=" com.components.mds.business" />
    <context:component-scan base-package=" com.components.mds.validation" />
    <context:component-scan base-package=" com.components.mds.dao" />
    <context:component-scan base-package=" com.components.mds.auth.service" />
    <context:component-scan base-package=" com.components.mds.auth.dao" />
    <context:component-scan base-package=" com.components.mds.audit.service" />
    <context:component-scan base-package=" com.components.mds.audit.dao" />
    <context:component-scan base-package=" com.components.mds.audit.vo" />
    <!--  DO not declare beans here just use annotations in class file -->
    <mvc:annotation-driven />

静态引用类也被注解了:

@Service

public class StaticReferenceServiceImpl 实现 StaticReferenceService { //SLF4J 日志处理程序 private static final Logger log = LoggerFactory.getLogger(StaticReferenceServiceImpl.class);

@Autowired
private StaticReferenceDao staticRefDao;

@Autowired
private MDSEhCacheManager<StaticReference,Map<String,ReferenceDataVO>> cacheManager;

看起来war中的类看不到WEB-INF\lib下war的lib文件夹中的jar中的类

如果唯一的变化是笔记本电脑升级到使用 Java 8,它会停止工作的任何建议

【问题讨论】:

    标签: spring spring-mvc


    【解决方案1】:

    错误日志显示它无法注入在com.mds.ui.controller.MDSBaseController.staticRefService 中定义的private com.components.mds.service.StaticReferenceService,您应该检查StaticReferenceService 是否使用诸如component, service 之类的任何Spring 注释进行注释

    【讨论】:

    • 是的 - 查看我更新的代码 sn-p。在安装 Java 8 并且在 RAD 中的旧 JDK1.7 中重新编译应用程序之前,它一直在工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-18
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    相关资源
    最近更新 更多