I am trying a to build a minimal gradle java project with Spring Boot and Spring Cloud AWS SQS but I can't get it to read from the queue.
These are my project files:
build.gradle:
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "spring-boot"
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")
classpath("io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE")
}
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-aws:1.1.0.RELEASE")
}
}
repositories {
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator:1.3.5.RELEASE")
compile("org.springframework.cloud:spring-cloud-starter-aws:1.1.0.RELEASE")
// if I don't add the line below, the annotation @MessageMapping is not found :(
// I would have expected that cloud-starter-aws would have taken care of it
compile("org.springframework.cloud:spring-cloud-aws-messaging:1.1.0.RELEASE")
// this has been added to fix an exception happening, please read below
compile("org.springframework.data:spring-data-commons:1.12.1.RELEASE")
}
Application.java:
package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application
{
public static void main(String[] args)
{
SpringApplication.run(Application.class, args);
}
}
QueueListener.java:
package com.test.sqs;
import java.util.logging.Logger;
import org.springframework.messaging.handler.annotation.MessageMapping;
import com.test.sqs.model.TestMessage;
public class QueueListener
{
@MessageMapping("test_queue")
private void receiveMessage(TestMessage testMessage)
{
System.out.println("Test message received: " + testMessage.getMessage());
}
}
application.yaml in src/main/resources:
cloud:
aws:
credentials:
accessKey: **********************
secretKey: **********************
region:
static: us-west-2
The application throws an exception when starting (but you can see the exception just in log debug mode!):
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.amazonaws.auth.profile.ProfilesConfigFile]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: AWS credential profiles file not found in the given path: C:\src\collector\default
but always in the log I can see it did pick up my credentials from the yaml file:
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.accessKey' in [systemProperties]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.accessKey' in [systemEnvironment]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.accessKey' in [random]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.accessKey' in [applicationConfigurationProperties]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Found key 'cloud.aws.credentials.accessKey' in [applicationConfigurationProperties] with type [String] and value '***'
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.secretKey' in [systemProperties]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.secretKey' in [systemEnvironment]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.secretKey' in [random]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Searching for key 'cloud.aws.credentials.secretKey' in [applicationConfigurationProperties]
2016-05-19 11:15:14.546 DEBUG 11704 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Found key 'cloud.aws.credentials.secretKey' in [applicationConfigurationProperties] with type [String] and value '***'
So I am not sure why it is looking somewhere else?
Also it's throwing this exception (always visible just if you are in logging debug mode):
java.lang.ClassNotFoundException: org.springframework.data.web.config.EnableSpringDataWebSupport
So I had to add in build.gradle
compile("org.springframework.data:spring-data-commons:1.12.1.RELEASE")
But now the exception is not there anymore but the program starts and ends without doing anything, and it's not printing logs anymore!
Some other facts:
- the Application.java is in the right package to let the component scan to work, so Spring should see the QueueListener class,
- the application.yaml is read correctly, if a put a wrong region it complains,
- if I put wrong credentials (wrong accessKey or/and wrong secretKey) it does not complain, so I don't think it is trying to connect to AWS at all.
I am not sure if line 34 of build.gradle:
compile("org.springframework.cloud:spring-cloud-starter-aws:1.1.0.RELEASE")
// if I don't add the line below, the annotation @MessageMapping is not found :(
// I would have expected that cloud-starter-aws would have taken care of it
compile("org.springframework.cloud:spring-cloud-aws-messaging:1.1.0.RELEASE")
// this has been added to fix an exception happening, please read below
compile("org.springframework.data:spring-data-commons:1.12.1.RELEASE")
could be a symptom of the issue, I would expect for all the needed libraries to be loaded by the cloud-starter-aws automatically.
What am I missing? Thank you!