Я новичок в Spring Integration, и я сделал пример приложения.Но я использовал XML для конфигурации.Я хочу использовать аннотации и сделать то же самое приложение.Заранее спасибо за помощь.
Ниже приведен мой файл конфигурации.
<?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.xsd
http://www.springframework.org/schema/integration/http
http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
<!-- CHANNEL -->
<int:channel id="requestChannel" />
<int:channel id="outputChannel" />
<int-http:inbound-gateway request-channel="requestChannel"
reply-channel="outputChannel" supported-methods="GET"
path="/welcome/{name}" payload-expression="#pathVariables.name">
<int-http:request-mapping consumes="application/json" produces="application/json" />
</int-http:inbound-gateway>
<int:service-activator ref="welcomeEndpoint"
method="get" input-channel="requestChannel" output-channel="outputChannel" />
Ниже приведен класс обслуживания
@Component
public class WelcomeEndpoint {
private Logger log = LoggerFactory.getLogger(this.getClass().getName());
public Message<?> get(Message<String> msg) {
String name = msg.getPayload();
// Log
log.info("Request with name = " + name);
// Get currentTime
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
String currentTime = dtf.format(now);
String strMsg = "Hello " + name + "! " + "Welcome to Spring Integration with Spring Boot!";
HelloMsg returnMsg = new HelloMsg(strMsg, currentTime);
return MessageBuilder.withPayload(returnMsg)
.copyHeadersIfAbsent(msg.getHeaders())
.setHeader("http_statusCode", HttpStatus.OK)
.build();
}
}
POJO
public class HelloMsg {
private String msg;
private String currentTime;
public HelloMsg(){}
public HelloMsg(String msg, String currentTime){
this.msg = msg;
this.currentTime = currentTime;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCurrentTime() {
return currentTime;
}
public void setCurrentTime(String currentTime) {
this.currentTime = currentTime;
}
}
Класс применения пружинной загрузки
@SpringBootApplication
@ImportResource("classpath:integration.xml")
public class SpringIntegrationApplication {
public static void main(String[] args) {
SpringApplication.run(SpringIntegrationApplication.class, args);
}
}