Announcement Announcement Module
Collapse
No announcement yet.
query regarding e-mail outbound-channel-adapter...!!! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • query regarding e-mail outbound-channel-adapter...!!!

    Hi,
    I am developing an application which is use to send the message of a channel as a email, let say that a particular
    message inside the channel will be mailed to anyone on his gmail id .The e-mail outbound-channel-adapter uses the SMTP protocol to send e-mail messages,For that I have an application but now I want that it annotation based configuration should be removed and all these setting should be there in the configuration file itself
    , no annotation is to be there in the application...the annotations used below are ...


    MailConfiguration.java
    *******************************

    Code:
    @Configuration
    public class MailConfiguration {
    
        @Bean
        public JavaMailSenderImpl mailSender() {
            JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
            mailSender.setHost("smtp.gmail.com");
            mailSender.setPort(587);
            mailSender.setUsername("[username]");
            mailSender.setPassword("[password]");
            Properties properties = new Properties();
            properties.setProperty("mail.smtp.starttls.enable", "true");
            properties.setProperty("mail.smtp.auth", "true");
            mailSender.setJavaMailProperties(properties);
            return mailSender;
        }
    }


    Smtp-Mail.xml
    *******************

    I want all these configuration in the xml file itself ,rite now I have current configuration such as ...

    Code:
    <?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:mail="http://www.springframework.org/schema/integration/mail"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/integration
        http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
    		http://www.springframework.org/schema/beans
    		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/integration/mail
    		http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd
    		http://www.springframework.org/schema/context
    		http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
      <context:component-scan base-package="com.apress.prospringintegration.social.mail"/>
    
      <int:channel id="input"/>
    
      <int:channel id="outboundMail"/>
    
      <mail:outbound-channel-adapter channel="outboundMail"
                                     mail-sender="mailSender"/>
    
      <mail:header-enricher input-channel="input" output-channel="outboundMail">
        <mail:to value="[email]"/>
        <mail:from value="[email]"/>
        <mail:subject value="Test"/>
      </mail:header-enricher>
    
    </beans>

    and the main file is SmtpMail.java
    ***************************************

    Code:
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.integration.Message;
    import org.springframework.integration.MessageChannel;
    import org.springframework.integration.support.MessageBuilder;
    
    public class SmtpMail {
    
        public static void main(String[] args) {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                    "/spring/mail/smtp-mail.xml", SmtpMail.class);
    
            MessageChannel input = context.getBean("input", MessageChannel.class);
    
            Message<String> message = MessageBuilder.withPayload("This is a test").build();
            input.send(message);
    
            context.stop();
        }
    }

    please advise me how to remove the annotations and set all the properties in the xml file itself....Thanks in advance

  • #2
    Before posting questions like this here, you MUST do some work on your own.

    The Spring Framework reference clearly describes how @Configuration is an alternative way to configure Spring Vs. XML; there are lots of blog posts on the internet that compare the two mechanisms.

    Look at the Spring Integration samples - https://github.com/SpringSource/spri...op3-config.xml

    Most people would look at the code snippet you provided and see how obvious it would be to do the same thing in XML.

    By the type of questions you keep asking here, it seems you might benefit from some formal training for the Spring Framework and Spring Integration...

    http://www.springsource.com/training

    Comment


    • #3
      Originally posted by Gary Russell View Post
      Before posting questions like this here, you MUST do some work on your own.

      The Spring Framework reference clearly describes how @Configuration is an alternative way to configure Spring Vs. XML; there are lots of blog posts on the internet that compare the two mechanisms.

      Look at the Spring Integration samples - https://github.com/SpringSource/spri...op3-config.xml

      Most people would look at the code snippet you provided and see how obvious it would be to do the same thing in XML.

      By the type of questions you keep asking here, it seems you might benefit from some formal training for the Spring Framework and Spring Integration...

      http://www.springsource.com/training
      HI Gary,
      I have gone through that but couldn't grasp that much in which it is shown that how to convert the annotation based configuration back again in xml based ...if anybody of you can have a look the below annotation based configuration and help me out in converting it into xml based configuration ...


      Code:
      @Configuration
      public class MailConfiguration {
      
          @Bean
          public JavaMailSenderImpl mailSender() {
              JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
              mailSender.setHost("smtp.gmail.com");
              mailSender.setPort(587);
              mailSender.setUsername("[username]");
              mailSender.setPassword("[password]");
              Properties properties = new Properties();
              properties.setProperty("mail.smtp.starttls.enable", "true");
              properties.setProperty("mail.smtp.auth", "true");
              mailSender.setJavaMailProperties(properties);
              return mailSender;
          }
      }
      Please help me out in converting it out back again in xml based configuration..!!

      Comment

      Working...
      X