Spring 集成 http-inbound-gateway / RequestMappingHandlerMapping
Spring Integration http-inbound-gateway / RequestMappingHandlerMapping
我是 Spring 集成的新手。我正在尝试使用 http-inbound-gateway 构建一个简单的应用程序。
下面是我得到的运行时异常。
java.lang.AbstractMethodError: Receiver class org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping 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);
}
}
POJO
@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>
问题是由于 Spring 集成在 POM.xml 和命名空间链接
中的版本不匹配
我是 Spring 集成的新手。我正在尝试使用 http-inbound-gateway 构建一个简单的应用程序。 下面是我得到的运行时异常。
java.lang.AbstractMethodError: Receiver class org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping 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);
}
}
POJO
@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>
问题是由于 Spring 集成在 POM.xml 和命名空间链接
中的版本不匹配