自动豆是无效的,但在弹簧容器中值



[已解决]在这种情况下,问题是我还没有将一些有用的液体包括在构建路径中,例如" jersey-spring4-2.28.jar"one_answers" spring-bridge-2.5.0.jar"。这些图书馆允许在球衣和春季之间整合。

我正在对Tomcat(9.0.16)进行Web应用程序,该应用程序揭示了用于数据通信的有用的REST服务(借助泽西岛2.28的帮助)。在管理这些服务的课程中,我使用了Spring(v5.1.5)将依赖项注入如下:

package it.learning.rest;
@Component
@Path("/")
public class GameClientCommsRestService {
@Autowired
@Qualifier("CommunicationBusiness")
private GameClientCommunication comm;
@GET
@Path("/test/check/bean")
@Produces(MediaType.TEXT_PLAIN)
public Response testCheckCommsBean() {
  StringBuilder sb = new StringBuilder();
  if (comm == null) {
    sb.append("GameClientCommunication instance is NULL!!");
  } else {
    sb.append("GameClientCommunication instance is NOT NULL ---> SUCCESSFULLY instantiated");
  }
  return getRestResponse(sb.toString());
}
}

注入依赖关系的类定义如下:

package it.learning.business.impl;
public class GameClientCommunicationBusiness implements GameClientCommunication {
  @Override
  public String processesMessage(String request, String remoteIpAddress) {
    // Processing input...
  }
}

XML配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
  <context:component-scan base-package="it.learning" />
  <context:annotation-config />
  <bean id="applicationContextProvider" class="it.learning.utils.spring.ApplicationContextProvider">
  </bean>
  <bean id="CommunicationBusiness" class="it.learning.business.impl.GameClientCommunicationBusiness">
  </bean>
</beans>

在应用程序启动时,tomcat和日志服务都没有记录任何问题,但是如果我致电

testcheckcommsbean()

它返回

" gameclientCommunication实例为null !!"

相反,如果我使用applicationContext对象获取与" CommunicationBusiness"关联的实例,则我获得了一个正常运行的对象。

日志表明,XML文件中注释的bean和XML文件中声明的bean都成功地创建并插入了弹簧容器中:

2019-03-19 13:06:00,343 debug org.springframework.beans.factory.xml.xml.xmlbeandefinitionreader-加载了ServletContext资源的7个bean定义[/web-inf/spring/spring/spring/appcontext.xml] 2019-03-19 13:06:00,362 debug org.springframework.beans.factory.xml.xml.xmlbeandefinitionReader-从ServletContext Resource [/web-inf/spring/spring/appcontextextextextbeans.xml]加载4个bean定义 2019-03-19 13:06:00,00,438 debug org.springframework.beans.factory.support.defaultlistablebeanfactory-创建Singleton bean'org.springframework.context.context.annotext.annotation.internalterconfiguratiguratigratigratigrationannonnonnonnonannonnonannonnonnonnotationprocessor'创建共享实例 2019-03-19 13:06:00,526 debug org.springframework.beans.factory.support.support.defaultlistablebeanfactory-创建Singleton bean'org.springframework.context.context.event.event.event.InternaleventListListListListEnerProperPropersor'的共享实例 2019-03-19 13:06:00,530 debug org.springframework.beans.factory.support.support.defaultlistablebeanfactory-创建Singleton bean'org.springframework.context.context.context.event.enternerternaleventlistlistlistlistlistleistlistenerfactory''创建共享实例 2019-03-19 13:06:00,532 debug org.springframework.beans.factory.support.defaultlistablebeanfactory-创建Singleton bean'org.springframework.context.context.annotation.annotation.internalautowiredirediredirediredannonnotation.internala bean' 2019-03-19 13:06:00,533 debug org.springframework.beans.factory.support.support.defaultlistablebeanfactory-创建singleton bean'org.springframework.context.context.annotation.annotation.internalscommonannotation.internalleternalscommonannotation.internallecommonannotation. 2019-03-19 13:06:00,537 debug org.springframework.beans.factory.support.defaultlistablebeanfactory-创建Singleton bean'org.springframework.context.context.annotext.annotation.annotation.internalspersistersistersistersiscencencencencencencencencencencencencencencencencencencencencencencencencencencencencEnnotpropercessor'创建共享实例 2019-03-19 13:06:00,549 debug org.springframework.beans.factory.support.defaultlistablebeanfactory-创建Singleton bean'gameClientCommSrestSrestService''创建共享实例 2019-03-19 13:06:00,579 debug org.springframework.beans.factory.support.defaultlistablebeanfactory-创建Singleton bean'CommunicationBusiness'的共享实例' 2019-03-19 13:06:00,582 debug org.springframework.beans.factory.support.defaultlistablebeanfactory-创建Singleton bean'spactionContextProvider的共享实例'

与报告中的报告不同为什么我的春季@Autowired Field Null?我从未使用"新"关键字实例化" gameclientCommunication"对象,因此我真的不明白为什么用@Autowired注释的字段为null。

感谢您的支持!

您可以在gameclientCommunicationBusiness类上尝试@component注释。

问题是您没有接线实现类。

相关内容

  • 没有找到相关文章

最新更新