当前位置: 首页 > 知识库问答 >
问题:

Spring集成http入站网关/RequestMappingHandlerMapping

邹博裕
2023-03-14

我不熟悉Spring集成。我正在尝试使用http入站网关构建一个简单的应用程序。下面是我得到的运行时异常。

java.lang.AbstractMethodError: Receiver class org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping$1 does not define or inherit an implementation of the resolved method abstract path()[Ljava/lang/String; of interface org.springframework.web.bind.annotation.RequestMapping.
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.createRequestMappingInfo(RequestMappingHandlerMapping.java:305) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping.getMappingForEndpoint(IntegrationRequestMappingHandlerMapping.java:160) ~[spring-integration-http-4.1.0.RELEASE.jar:na]
at org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping.detectHandlerMethods(IntegrationRequestMappingHandlerMapping.java:98) ~[spring-integration-http-4.1.0.RELEASE.jar:na]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.processCandidateBean(AbstractHandlerMethodMapping.java:249) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:208) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:196) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:164) ~[spring-webmvc-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping.onApplicationEvent(IntegrationRequestMappingHandlerMapping.java:177) ~[spring-integration-http-4.1.0.RELEASE.jar:na]
at org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping.onApplicationEvent(IntegrationRequestMappingHandlerMapping.java:71) ~[spring-integration-http-4.1.0.RELEASE.jar:na]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:398) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:355) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.cerner.api.MedicationManagementApplication.main(MedicationManagementApplication.java:12) ~[classes/:na]

下面是代码文件。

@SpringBootApplication
@ImportResource("classpath:integration.xml")
public class MedicationManagementApplication {

public static void main(String[] args) {
    SpringApplication.run(MedicationManagementApplication.class, args);
}
}

波约

@Entity
public class Medicine {

@Id
private String medId;

private String medName;
private String expDate;

public Medicine(String medId, String medName, String expDate) {
    this.medId = medId;
    this.medName = medName;
    this.expDate = expDate;
}
public Medicine() {

}
public String getMedId() {
    return medId;
}
public void setMedId(String medId) {
    this.medId = medId;
}
public String getMedName() {
    return medName;
}
public void setMedName(String medName) {
    this.medName = medName;
}
public String getExpDate() {
    return expDate;
}
public void setExpDate(String expDate) {
    this.expDate = expDate;
}

@Override
public String toString() {
    return "Medicine [medId=" + medId + ", medName=" + medName + ", 
expDate=" + expDate + "]";
}

}

服务

@Service
public class MedicineService {

@Autowired
private MediceneRepository medicineRepo;

private Logger log = LoggerFactory.getLogger(this.getClass().getName());

public List<Medicine> getAllMedicines() {
    System.out.println("== Service called==");
    List<Medicine> medicine = new ArrayList<Medicine>();
    medicineRepo.findAll().forEach(medicine::add);
    log.info("Returning from service with medicine data");
    return medicine;
}

}

服务激活器

@Component("medicineServiceActivator")
public class MedicineServiceActivator {

private Logger log = LoggerFactory.getLogger(this.getClass().getName());

@Autowired
private MedicineService medicineService;

public Message<?> get(Message<?> msg) {
    log.info("GET method");
    System.out.println("===== get method called ====");
    List<Medicine> medLst = medicineService.getAllMedicines();
    return 
MessageBuilder.withPayload(medLst).copyHeadersIfAbsent(msg.getHeaders())
            .setHeader("http_statusCode", HttpStatus.OK).build();
}

}

存储库

public interface MediceneRepository extends CrudRepository<Medicine, String> 
{

}

请帮助我,我正在试图找到异常发生的原因,但无法解决。提前谢谢。

集成文件。

<?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:int="http://www.springframework.org/schema/integration"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-4.1.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration- 
http-4.1.xsd">
<int:channel id="responseChannel" />
<int-http:inbound-gateway request-channel="requestChannel" reply- 
channel="responseChannel" supported-methods="GET" path="/getAllMedicines">
<int-http:request-mapping consumes="application/json" 
produces="application/json" /></int-http:inbound-gateway>
<int:service-activator ref="medicineServiceActivator" method="get" input- 
channel="requestChannel" output-channel="responseChannel" />
</beans>

共有1个答案

徐皓君
2023-03-14

问题是由于POM中Spring集成的版本不匹配。xml和命名空间链接

 类似资料:
  • 我尝试使用以下代码,得到了回应:状态:405方法不允许。这是我的Http请求:http://localhost:8090/services/test?name=test.代码或http请求有什么问题?

  • 我正在尝试将spring集成配置为向队列发送消息,然后接收消息,即非常简单的事情: 我认为解耦所必需的是在流程的两端都有一个消息网关。因此,我的第一次尝试(有效)如下所示: 其中MessageReceiverHandler()是扩展AbstractMessageHandler的bean。 所以上面我们有一个用于出站消息的消息网关。我假设我们也应该有一个用于入站消息的网关,允许我们将传入消息处理与应

  • 我有一个http出站网关,它将json消息发布到rest服务,现在rest将以json消息类型的http错误状态响应,以防我们的应用程序捕获任何错误。在将json消息发布到rest服务并获得http成功状态的愉快场景中,我们的应用程序也应该捕获json消息。 现在我通过Spring集成实现了什么,我能够发送消息并获得成功响应并捕获它,但在错误状态下Spring行为会抛出异常,我如何更改行为? 如果

  • 我正在将SpringBoot 2.0与Spring Integr5.0.3一起使用,并且我的HTTP. in边界网关有问题。我的目标是验证发布到网关的JSON,因为请求pojo由强制字段组成。 有没有一种简单的方法来验证pojo中的字段是否已设置?我已经测试过的是使用@NotNull-SpringValidation,但它似乎不受Spring集成的支持。 你好smoothny

  • 我试图实现某种代理作为我的数据流的一部分,我想在我的入站网关上接收超文本传输协议请求,并通过出站网关传递它。我想保留所有查询字符串参数。我的网关配置是: 我预计它的工作如下: > GET/services/normalization q=cat 入站网关接收请求,并将其通过搜索请求通道发送到出站网关。 出站网关向外部服务发送整个请求: 获取/查询q=cat 但实际上,出站网关发送不包含任何查询参数

  • 我正在尝试使用Spring Integration int-http:inbound-gateway测试Inbound http gatway: 我的Web.xml: 使用RestTemplate,我试图向网关发出POST请求: 那个 我总是得到没有找到404,你能给我一些提示吗? 非常感谢!