java - AWS SNS sending with Spring Cloud. Trying to understand -


i newbie in spring. trying learn through practice implementing simple push server ios app documentation , samples on github. wrong , cannot understand what. me, please?

so snssendercontroller code is:

import org.slf4j.logger; import org.slf4j.loggerfactory; import org.springframework.beans.factory.annotation.autowired; import org.springframework.cloud.aws.messaging.core.notificationmessagingtemplate; import org.springframework.http.httpstatus; import org.springframework.web.bind.annotation.*;  @restcontroller                 @requestmapping("/sns")         public class snssendercontroller {            private static final logger thelogger = loggerfactory.getlogger(snssendercontroller.class);     private final notificationmessagingtemplate notificationmessagingtemplate;      @autowired     public snssendercontroller(notificationmessagingtemplate notificationmessagingtemplate) {         this.notificationmessagingtemplate = notificationmessagingtemplate;     }      @requestmapping(value = "/send", method = requestmethod.post)     @responsestatus(httpstatus.ok)     public void sendnotification(@requestbody snsnotification notification) {         thelogger.debug("going send notification {}", notification);          this.notificationmessagingtemplate.sendnotification("snstopic", notification.getmessage(), notification.getsubject());     }  } 

my snsnotification class:

import com.fasterxml.jackson.annotation.jsoncreator; import com.fasterxml.jackson.annotation.jsonproperty;  public class snsnotification {      private final string subject;     private final string message;      @jsoncreator     public snsnotification(@jsonproperty("subject") string subject, @jsonproperty("message") string message) {         this.subject = subject;         this.message = message;     }      public string getsubject() {         return this.subject;     }      public string getmessage() {         return this.message;     }      @override     public string tostring() {         return "snsnotification{" + "subject='" + this.subject + '\'' + ", message='" + this.message + '\'' + '}';     }  } 

beans:

<?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:aws-context="http://www.springframework.org/schema/cloud/aws/context"        xmlns:aws-messaging="http://www.springframework.org/schema/cloud/aws/messaging"        xsi:schemalocation="http://www.springframework.org/schema/beans                            http://www.springframework.org/schema/beans/spring-beans.xsd                            http://www.springframework.org/schema/cloud/aws/context                            http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context-1.0.xsd                            http://www.springframework.org/schema/cloud/aws/messaging                            http://www.springframework.org/schema/cloud/aws/messaging/spring-cloud-aws-messaging-1.0.xsd">         <!-- define global credentials aws clients -->        <aws-context:context-credentials>               <aws-context:instance-profile-credentials/>               <aws-context:simple-credentials access-key="${accesskey}"                                               secret-key="${secretkey}"/>        </aws-context:context-credentials>         <!-- messaging-->        <aws-messaging:notification-messaging-template id="notificationmessagingtemplate" />  </beans> 

the main app code is:

import com.amazonaws.services.sns.amazonsns; import org.springframework.boot.springapplication; import org.springframework.boot.autoconfigure.enableautoconfiguration; import org.springframework.boot.autoconfigure.springbootapplication; import org.springframework.cloud.aws.core.env.resourceidresolver; import org.springframework.cloud.aws.messaging.core.notificationmessagingtemplate; import org.springframework.context.annotation.bean; import org.springframework.context.annotation.componentscan;  @springbootapplication @componentscan @enableautoconfiguration  public class mysenderapplication {      public static void main(string[] args) {         springapplication.run(mysenderapplication.class, args);     }      @bean     public notificationmessagingtemplate notificationmessagingtemplate(amazonsns amazonsns, resourceidresolver resourceidresolver) {         return new notificationmessagingtemplate(amazonsns, resourceidresolver);     } } 

and crash start lot of errors. please!

update:

i don't know why, starts work... 2 more questions.

  1. according spring cloud docs connection settings aws should in application.properties. put there keys cloud.aws.credentials.accesskey , cloud.aws.credentials.secretkey there error there: "cannot resolve configuration property". why so? did miss?
  2. according spring docs can make "notificationmessagingtemplate" there instead of annotation @bean, code works @bean annotation in code. why so?


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -