How to convert Spring Integration application in Annotation?












1















I am new to Spring Integration and i have done a sample application. But i have used XML for configuration. I want to use annotations and do the same application.
Thanks in advance for the help.



Below is my Configuration file.



    <?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" />




Below is the service class



@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;
}


}



Spring Boot Application Class



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

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


}










share|improve this question

























  • Refer:Java DSL: github.com/spring-projects/spring-integration-java-dsl/wiki/…

    – Sundararaj Govindasamy
    Nov 20 '18 at 19:07


















1















I am new to Spring Integration and i have done a sample application. But i have used XML for configuration. I want to use annotations and do the same application.
Thanks in advance for the help.



Below is my Configuration file.



    <?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" />




Below is the service class



@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;
}


}



Spring Boot Application Class



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

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


}










share|improve this question

























  • Refer:Java DSL: github.com/spring-projects/spring-integration-java-dsl/wiki/…

    – Sundararaj Govindasamy
    Nov 20 '18 at 19:07
















1












1








1








I am new to Spring Integration and i have done a sample application. But i have used XML for configuration. I want to use annotations and do the same application.
Thanks in advance for the help.



Below is my Configuration file.



    <?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" />




Below is the service class



@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;
}


}



Spring Boot Application Class



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

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


}










share|improve this question
















I am new to Spring Integration and i have done a sample application. But i have used XML for configuration. I want to use annotations and do the same application.
Thanks in advance for the help.



Below is my Configuration file.



    <?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" />




Below is the service class



@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;
}


}



Spring Boot Application Class



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

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


}







java spring spring-boot spring-integration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 19:09









Sundararaj Govindasamy

4,24032553




4,24032553










asked Nov 20 '18 at 18:42









SonuSonu

648




648













  • Refer:Java DSL: github.com/spring-projects/spring-integration-java-dsl/wiki/…

    – Sundararaj Govindasamy
    Nov 20 '18 at 19:07





















  • Refer:Java DSL: github.com/spring-projects/spring-integration-java-dsl/wiki/…

    – Sundararaj Govindasamy
    Nov 20 '18 at 19:07



















Refer:Java DSL: github.com/spring-projects/spring-integration-java-dsl/wiki/…

– Sundararaj Govindasamy
Nov 20 '18 at 19:07







Refer:Java DSL: github.com/spring-projects/spring-integration-java-dsl/wiki/…

– Sundararaj Govindasamy
Nov 20 '18 at 19:07














1 Answer
1






active

oldest

votes


















0














See the reference manual Java DSL, Finding Class Names for Java and DSL Configuration and annotation support.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399499%2fhow-to-convert-spring-integration-application-in-annotation%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    See the reference manual Java DSL, Finding Class Names for Java and DSL Configuration and annotation support.






    share|improve this answer




























      0














      See the reference manual Java DSL, Finding Class Names for Java and DSL Configuration and annotation support.






      share|improve this answer


























        0












        0








        0







        See the reference manual Java DSL, Finding Class Names for Java and DSL Configuration and annotation support.






        share|improve this answer













        See the reference manual Java DSL, Finding Class Names for Java and DSL Configuration and annotation support.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 19:08









        Gary RussellGary Russell

        79.5k74471




        79.5k74471






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399499%2fhow-to-convert-spring-integration-application-in-annotation%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy