Invalid character "/" in path section spring cloud gcp binder - spring-boot

I am trying to listen to one pubsub subscription via gcp binder
build.gradle
ext {
set('springCloudGcpVersion', "3.4.2")
set('springCloudVersion', "2021.0.5")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.google.cloud:spring-cloud-gcp-starter'
implementation 'com.google.cloud:spring-cloud-gcp-starter-pubsub'
implementation 'com.google.cloud:spring-cloud-gcp-pubsub-stream-binder'
implementation 'com.google.cloud:spring-cloud-gcp-starter-storage'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "com.google.cloud:spring-cloud-gcp-dependencies:${springCloudGcpVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
application yml
spring:
cloud:
gcp:
credentials.location: 'classpath:creds.json'
stream:
function:
definition: myConsumer
bindings:
catalogConsumer-in-0:
destination: projects/projectid/subscriptions/subid
binder: pubsub
group: muygroup
content-type: application/json
Code:
#Bean
public Consumer<Message<String>> myConsumer() {
return message -> {
log.info("Message has been received {}, {}", message.getPayload(),
message.getHeaders().get("heh"));
};
}
error:
Caused by: com.google.api.pathtemplate.ValidationException: Invalid character "/" in path section "projects/projectid/subscriptions/subid"
at com.google.api.pathtemplate.PathTemplate.encodeUrl(PathTemplate.java:1099) ~[api-common-2.4.0.jar:2.4.0]
at com.google.api.pathtemplate.PathTemplate.instantiate(PathTemplate.java:768) ~[api-common-2.4.0.jar:2.4.0]
at com.google.api.pathtemplate.PathTemplate.instantiate(PathTemplate.java:691) ~[api-common-2.4.0.jar:2.4.0]
at com.google.pubsub.v1.TopicName.toString(TopicName.java:173) ~[proto-google-cloud-pubsub-v1-1.105.0.jar:1.105.0]
at com.google.cloud.pubsub.v1.TopicAdminClient.getTopic(TopicAdminClient.java:557) ~[google-cloud-pubsub-1.123.0.jar:1.123.0]
at com.google.cloud.spring.pubsub.PubSubAdmin.getTopic(PubSubAdmin.java:137) ~[spring-cloud-gcp-pubsub-3.4.2.jar:3.4.2]
at com.google.cloud.spring.stream.binder.pubsub.provisioning.PubSubChannelProvisioner.ensureTopicExists(PubSubChannelProvisioner.java:136) ~[spring-cloud-gcp-pubsub-stream-binder-3.4.2.jar:3.4.2]
at com.google.cloud.spring.stream.binder.pubsub.provisioning.PubSubChannelProvisioner.provisionConsumerDestination(PubSubChannelProvisioner.java:82) ~[spring-cloud-gcp-pubsub-stream-binder-3.4.2.jar:3.4.2]
at com.google.cloud.spring.stream.binder.pubsub.provisioning.PubSubChannelProvisioner.provisionConsumerDestination(PubSubChannelProvisioner.java:42) ~[spring-cloud-gcp-pubsub-stream-binder-3.4.2.jar:3.4.2]
at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindConsumer(AbstractMessageChannelBinder.java:428) ~[spring-cloud-stream-3.2.6.jar:3.2.6]
... 11 common frames omitted
The subscription path is valid
But I am getting this exception

Related

MapStruct throws exception when try to build project

There is springboot application with gradle and try to convert one object to another using MapStruct, but there is exception in compile time
I added sctruct dependencies in build.gradle by instruction in bottom
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'my.bot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.6'
implementation 'javax.jws:javax.jws-api:1.1'
implementation 'org.mapstruct:mapstruct:1.5.3.Final'
implementation 'org.mapstruct:mapstruct-processor:1.5.3.Final'
}
tasks.named('test') {
useJUnitPlatform()
}
tasks.withType(JavaCompile) {
options.compilerArgs = [
'-Amapstruct.suppressGeneratorTimestamp=true'
]
}
My interface look like this
#Mapper
public interface DeviceAgentMessageMapper {
#Mapping(source = "gamma", target = "message")
AgentMessage toAgentMessage(Device device);
}
But when try to start application or call build gradle job, there is error message:
The following options were not recognized by any processor: '[mapstruct.suppressGeneratorTimestamp]'
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException at DefaultListableBeanFactory.java:1801

How to fix Could not find or load main class in Spring boot gradle.build?

Im new in gradle and i receive and error about my main class is Could not find or load main class i tried to fix it but doest work.
plugins {
id 'org.springframework.boot' version '2.6.9'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.notification'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.3")
}
dependencies {
implementation 'io.awspring.cloud:spring-cloud-aws-context:2.3.1'
implementation 'io.awspring.cloud:spring-cloud-aws-autoconfigure:2.3.1'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-stream'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
springBoot {
mainClass = 'com.notification.NotificationServiceApplication'
}
Error
Error: Could not find or load main class com.notifcation.NotificationServiceApplication
Caused by: java.lang.ClassNotFoundException: com.notifcation.NotificationServiceApplication
Disregard this post question. I just restart my IDE

Use main Gradle project to define all dependencies versions

I want to create one main Gradle project which hosts all project dependencies:
Main Gradle project:
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven-publish'
}
group = 'com.parent.dependencies'
version = '0.0.1'
sourceCompatibility = '11'
ext {
set('springCloudVersion', "2021.0.1")
artifactory_contextUrl = "http://192.168.1.112/repository"
}
repositories {
mavenCentral()
maven {
url "${artifactory_contextUrl}/plugins-release"
allowInsecureProtocol = true
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.threeten:threetenbp:1.5.1'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
// Swagger
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation 'org.springframework.boot:spring-boot-starter-hateoas:2.6.3'
implementation group: 'com.netflix.hystrix', name: 'hystrix-core', version: '1.5.18'
implementation group: 'org.springframework.security', name: 'spring-security-core', version: '5.6.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}
bootJar {
enabled = false
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
test {
useJUnitPlatform()
}
Sub project which will read all dependencies versions from parent Gradle project:
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'maven-publish'
}
group = 'com.child'
version = '0.0.1'
sourceCompatibility = '11'
ext {
artifactory_contextUrl = "http://192.168.1.112/repository"
}
repositories {
mavenCentral()
maven {
url "${artifactory_contextUrl}/plugins-release"
allowInsecureProtocol = true
}
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.threeten:threetenbp'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
// Swagger
implementation 'io.springfox:springfox-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'com.netflix.hystrix:hystrix-core'
implementation 'org.springframework.security:spring-security-core'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
dependencyManagement {
imports {
mavenBom "com.parent:com-parent-dependencies:0.0.1"
}
}
bootJar {
enabled = false
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
test {
useJUnitPlatform()
}
When I try to compile the child project I get error:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find org.threeten:threetenbp:.
Required by:
project :
> Could not find io.springfox:springfox-boot-starter:.
Required by:
project :
> Could not find com.netflix.hystrix:hystrix-core:.
Required by:
project :
Do you know how I can define properly the parent Gradle project with all dependencies versions and use the child project without defining dependencies versions?
There’s a relatively new Gradle feature called “version catalogs”. With those you can centrally declare dependencies that you’d like to share between multiple projects of your build (or even between different builds).
In your concrete example, you’d add something like the following to your settings.gradle file:
dependencyResolutionManagement {
versionCatalogs {
libs {
library('spring-cloud-bom', 'org.springframework.cloud:spring-cloud-dependencies:2021.0.1')
library('spring-cloud-starter', 'org.springframework.cloud', 'spring-cloud-starter-netflix-eureka-client').withoutVersion()
library('spring-boot-starter-validation', 'org.springframework.boot', 'spring-boot-starter-validation').withoutVersion()
library('spring-boot-starter-test', 'org.springframework.boot', 'spring-boot-starter-test').withoutVersion()
library('threetenbp', 'org.threeten:threetenbp:1.5.1')
library('spring-boot-starter-actuator', 'org.springframework.boot', 'spring-boot-starter-actuator').withoutVersion()
library('lombok', 'org.projectlombok:lombok:1.18.22')
library('springfox-boot-starter', 'io.springfox:springfox-boot-starter:3.0.0')
library('spring-boot-starter-hateoas', 'org.springframework.boot:spring-boot-starter-hateoas:2.6.3')
library('hysterix-core', 'com.netflix.hystrix:hystrix-core:1.5.18')
library('spring-security-core', 'org.springframework.security:spring-security-core:5.6.1')
library('junit-jupiter-api', 'org.junit.jupiter:junit-jupiter-api:5.8.2')
library('junit-jupiter-engine', 'org.junit.jupiter:junit-jupiter-engine:5.8.2')
}
}
}
Then, in both build.gradle files, you’d replace your dependencies blocks with the following:
dependencies {
implementation libs.spring.cloud.starter
implementation libs.spring.boot.starter.validation
testImplementation libs.spring.boot.starter.test
implementation libs.threetenbp
implementation libs.spring.boot.starter.actuator
// Lombok
compileOnly libs.lombok
annotationProcessor libs.lombok
testCompileOnly libs.lombok
testAnnotationProcessor libs.lombok
// Swagger
implementation libs.springfox.boot.starter
implementation libs.spring.boot.starter.hateoas
implementation libs.hysterix.core
implementation libs.spring.security.core
testImplementation libs.junit.jupiter.api
testRuntimeOnly libs.junit.jupiter.engine
}
As you’re using a Maven BOM for Spring, you’ll also have to use the following updated dependencyManagement block in all projects:
dependencyManagement {
imports {
mavenBom libs.spring.cloud.bom.get().toString()
}
resolutionStrategy {
cacheDynamicVersionsFor 0, "seconds"
cacheChangingModulesFor 0, "seconds"
}
}
That should be it. I could successfully test your sample build configurations with my updates at least on Gradle 7.4.

Spring Cloud Stream Configuration classes are not being loaded

After updating from Spring Boot 2.0.6 / Spring Cloud Finchley.RELEASE to Spring Boot 2.1.3 / Spring Cloud Greenwich.SR1, I am experiencing a very odd configuration / component scanning issue.
The application is structured as follows:
main-application
messaging-lib
commons-lib
Main application is annotated with #SpringBootApplication(scanBasePackages = {"com.app.libs", "com.app"}), where the com.app packages are those under the main-application, while com.app.libs are the packages of the libs.
The commons-lib configuration which is simply a framework-esque library has the following main configuration entrypoint:
package com.app.libs.commons
#Target(ElementType.TYPE)
#Retention(RetentionPolicy.RUNTIME)
#Documented
#Inherited
#Import(CommonsConfiguration.class)
public #interface EnableCommons {
}
With CommonsConfiguration having:
package com.app.libs.commons.config
#Configuration
#ConditionalOnProperty(value = "com.app.config.commons", matchIfMissing = true)
#ComponentScan(basePackages = "com.app.libs.commons")
public class FrameworkConfiguration {
This way, I can basically annotate a single configuration class in my main-application and have it pick up common beans.
The messaging-lib configuration which uses Spring Cloud Stream has the following configurations:
#Configuration
#Import({ CustomBinding.class })
#PropertySource("classpath:kafka.properties")
#EnableBinding(Source.class)
#EnableAutoConfiguration
public class BindingConfiguration {
}
The cloud stream configuration is as follows:
spring.cloud.stream.bindings.output.destination=${spring.application.name}
spring.cloud.stream.kafka.bindings.output.producer.sync=true
spring.cloud.stream.default.group=${spring.application.name}
spring.cloud.stream.default.producer.partitionCount=9
spring.cloud.stream.default.producer.partitionKeyExpression=headers.entityId
spring.cloud.stream.kafka.binder.autoAddPartitions=true
spring.cloud.stream.kafka.binder.autoCreateTopics=false
When starting the application, the following error message is produced:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.cloud.stream.default.producer.partition-key-expression' to org.springframework.expression.Expression:
Property: spring.cloud.stream.default.producer.partitionkeyexpression
Value: headers.entityId
Origin: "spring.cloud.stream.default.producer.partitionKeyExpression" from property source "class path resource [kafka.properties]"
Reason: No converter found capable of converting from type [java.lang.String] to type [#com.fasterxml.jackson.databind.annotation.JsonSerialize org.springframework.expression.Expression]
Action:
Update your application's configuration
After some looking through the source code, I've noticed that the SpelConverter in question is the one that is supposed to be initialized in SpelExpressionConverterConfiguration. Indeed, if I add #Import({ SpelExpressionConverterConfiguration.class }) or #Import({ BindingServiceConfiguration }) (the #Configuration class that imports the SpelExpressionConverterConfiguration) to my BindingConfiguration, the converter seems to get initialized. However, another error is then produced:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type 'org.springframework.messaging.core.DestinationResolver' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'binderAwareChannelResolver' in 'BindingServiceConfiguration' not loaded because #ConditionalOnBean (types: org.springframework.cloud.stream.binder.BinderTypeRegistry; SearchStrategy: current) did not find any beans of type org.springframework.cloud.stream.binder.BinderTypeRegistry
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.messaging.core.DestinationResolver' in your configuration.
I'm not quite sure what seems to be going on. When debugging, it seems that both BindingBeansRegistrar and BinderFactoryConfiguration (the classes imported through #EnableBinding) are loaded - yet no scanning occurs and the rest of the component scanning simply does not seem to happen.
I've tried importing the configuration classes and/or scanning the packages myself, but in both cases I am still missing the DestinationResolver bean, although it should have been initialized.
I've noted that, prior to the update, there were also some issues: I had to import BindingServiceConfiguration, BinderFactoryConfiguration, and SpelExpressionConverterConfiguration manually as well.
Would anybody have pointers as to what could be causing this issue?
EDIT: Here are the build.grade files (some includes are omitted for brevity):
Application build.gradle
apply from: new File(project(':scripts').projectDir, '/service-impl.gradle')
dependencies {
implementation project(':dependency-A')
implementation project(':dependency-B')
implementation project(':messaging-library')
testImplementation 'org.springframework.cloud:spring-cloud-stream-test-support'
}
service-impl.gradle contents:
buildscript {
apply from: new File(project(':buildscripts').projectDir, '/repositories.gradle') // Repository definitions
apply from: new File(project(':buildscripts').projectDir, '/dm-boot.gradle') // DM via spring boot plugin
apply from: new File(project(':buildscripts').projectDir, '/dm-versions.gradle') // DM versions
}
configurations {
all*.exclude module: 'spring-boot-starter-tomcat'
all*.exclude group: 'org.apache.bval'
}
artifacts {
archives bootJar
}
dependencies {
compileOnly 'org.projectlombok:lombok'
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-jetty'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-cache'
compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
compile 'org.springframework.cloud:spring-cloud-starter-config'
testCompile 'junit:junit'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompileOnly 'org.projectlombok:lombok'
compile 'net.logstash.logback:logstash-logback-encoder'
}
Commons Library build.gradle
apply from: new File(project(':buildscripts').projectDir, '/repositories.gradle') // Repository definitions
apply from: new File(project(':buildscripts').projectDir, '/dm-plain.gradle') // DM via spring boot plugin
apply from: new File(project(':buildscripts').projectDir, '/dm-versions.gradle') // DM versions
dependencies {
api 'com.restfb:restfb:2.3.0'
api 'commons-io:commons-io'
implementation 'com.jcraft:jsch:0.1.54'
//lombok
compileOnly 'org.projectlombok:lombok'
//spring
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation 'org.springframework.boot:spring-boot-starter-security'
api 'org.springframework.security:spring-security-core'
api 'org.springframework.security:spring-security-web'
api 'org.springframework:spring-jdbc'
api 'org.springframework.boot:spring-boot-starter-actuator'
//thrift modules
compileOnly 'com.facebook.swift:swift-codec'
compileOnly 'com.facebook.swift:swift-service'
//db modules
api 'org.postgresql:postgresql'
api 'org.flywaydb:flyway-core'
api 'com.zaxxer:HikariCP'
api 'org.jooq:jooq'
//embedded pg modules
compileOnly 'com.opentable.components:otj-pg-embedded'
api group: 'net.minidev', name: 'json-smart', version: '2.2.1'
api group: 'org.json', name: 'json', version: '20140107'
//tests
testImplementation 'junit:junit'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.opentable.components:otj-pg-embedded'
testImplementation 'org.springframework.security:spring-security-core'
testImplementation 'org.springframework.security:spring-security-web'
testImplementation 'org.springframework.security:spring-security-config'
testImplementation 'org.springframework:spring-jdbc'
testImplementation 'org.springframework.boot:spring-boot-starter-actuator'
testImplementation 'org.apache.sshd:sshd-core:1.7.0' // sftpFileTransfer testing - embedded sftp server
testCompileOnly 'org.projectlombok:lombok'
testCompileOnly 'javax.servlet:javax.servlet-api'
}
Messaging Lib build.gradle (used as a standalone lib, hence does not use the above .gradle files)
buildscript {
ext {
springBootVersion = '2.1.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply from: new File(rootDir.parentFile, 'buildscripts/publish.gradle')
apply from: new File(rootDir.parentFile, 'buildscripts/coverage.gradle')
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.app.libs.messaging'
version = '0.0.3'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
ext {
springCloudVersion = 'Greenwich.SR1'
jacksonVersion = '2.9.6'
lombokVersion = '1.16.18'
jooqVersion = '3.11.2'
flywayVersion = '5.2.1'
}
dependencies {
compile 'org.aspectj:aspectjweaver'
compile 'org.springframework:spring-tx'
compile 'org.springframework.cloud:spring-cloud-stream'
compile 'org.springframework.cloud:spring-cloud-stream-binder-kafka'
compile 'org.apache.commons:commons-lang3:3.5'
compile 'org.javassist:javassist:3.22.0-GA'
compile "org.flywaydb:flyway-core:${flywayVersion}"
compileOnly "org.jooq:jooq:${jooqVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.springframework.boot:spring-boot-starter-json'
testCompile 'org.springframework.cloud:spring-cloud-stream-test-support'
testCompile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
testCompile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
testCompile 'junit:junit:4.12'
testCompile "org.jooq:jooq:${jooqVersion}"
testCompile "org.flywaydb:flyway-core:${flywayVersion}"
testCompile 'org.postgresql:postgresql:42.2.2'
testCompile 'com.opentable.components:otj-pg-embedded:0.13.0'
testCompile 'org.springframework:spring-jdbc'
}
dependencyManagement {
// disable maven exclusion to enhance gradle import performance
// https://github.com/spring-gradle-plugins/dependency-management-plugin/issues/153
applyMavenExclusions = false
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
jar.enabled = true
bootJar.enabled = false
I've tried to omit any files that I think should be unrelated.

Cloud client config application do not get properties from Config Server Spring boot

I have a web application and I want to use Server Configuration from Spring Boot.
Both applications are located on localhost machine. I have made first two applications from scratch and they worked together, but when i use the client that has many dependencies in it (not just the cloud-config and web dependency) it is not working anymore. How do I know? I have a variable in properties file in server and i try to use it in my client with #Value("${atena}")
and error appears java.lang.IllegalArgumentException: Could not resolve placeholder 'atena' in value "${atena}".
The following image is my server config application.
The main class from server has the following annotation #EnableConfigServer
In atena-config.yml I have only the variable name:
atena: 'Hellllloooooo'
bootstrap.yml content
server:
port: 9000
spring:
profiles:
active: native
and build.gradle dependencies:
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I am sure the server it is correct, something is wrong with my client.
--------------------> Client side
I have a restcontroller:
#RestController
#RequestMapping("/songs")
public class SongController {
#Value("${atena}")
String variable;
#GetMapping(value="/check-from")
public String viewVariable(){
return variable;
}
}
in which I am trying to get the variable from server config.
bootstrap.yml from client
spring:
application:
name: atena-config
cloud:
config:
uri: http://localhost:9000
And lastly the build.gradle from client:
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
implementation 'org.springframework.boot:spring-boot-starter'
implementation('org.apache.tomcat:tomcat-jdbc:9.0.10')
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation('org.mybatis:mybatis:3.4.6')
implementation('org.mybatis:mybatis-spring:1.3.2')
implementation('org.springframework.boot:spring-boot-starter-jdbc')
implementation('org.springframework.cloud:spring-cloud-starter-config')
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I really don't know what happen, I am pretty sure that these dependencies are the problem, but I have not figured out which one, i can not exclude any of them, because I am using them in project.
Never mind. I have fixed it. Indeed the problem was from my dependencies, my gradle.build was with problem. I have created a new project with spring initializer having all the dependencies and copied the new gradle.build from there and now is it working.
This is the new build.gradle from client
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', 'Greenwich.RELEASE')
}
dependencies {
compile 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.0'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

Resources