I am running a spring cloud config server.I follow the user guide,and successfully start it up,it can load the configuration from github config-repo/licensingservice/licensingservice.yml
.I can use the /decrypt and /encript endpoints ,but when I run http://localhost:8888/licensingservice/default
it always decrypts the sensitive message
spring.datasource.password: "{cipher}4788dfe1ccbe6485934aec2ffeddb06163ea3d616df5fd75be96aadd4df1da91" into
"spring.datasource.password": "p0stgr#s"
I have put spring.cloud.config.server.encrypt.enabled=false in bootstrap.yml, and can see it by the
localhost:8888/actuator/env
the configuration on the github:
example.property: "I AM IN THE DEFAULT"
spring.jpa.database: "POSTGRESQL"
spring.datasource.platform: "postgres"
spring.jpa.show-sql: "true"
spring.database.driverClassName: "org.postgresql.Driver"
spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_local"
spring.datasource.username: "postgres"
spring.datasource.password: "{cipher}4788dfe1ccbe6485934aec2ffeddb06163ea3d616df5fd75be96aadd4df1da91"
spring.datasource.testWhileIdle: "true"
spring.datasource.validationQuery: "SELECT 1"
spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"
redis.server: "redis"
redis.port: "6379"
signing.key: "345345fsdfsf5345"
configuration get from postman:
{
"name": "licensingservice",
"profiles": [
"default"
],
"label": null,
"version": "56d63a8c0c3dcb0c5c93db1f00cf71856371db8b",
"state": null,
"propertySources": [
{
"name": "https://github.com/carnellj/config-repo//licensingservice/licensingservice.yml",
"source": {
"example.property": "I AM IN THE DEFAULT",
"spring.jpa.database": "POSTGRESQL",
"spring.datasource.platform": "postgres",
"spring.jpa.show-sql": "true",
"spring.database.driverClassName": "org.postgresql.Driver",
"spring.datasource.url": "jdbc:postgresql://database:5432/eagle_eye_local",
"spring.datasource.username": "postgres",
"spring.datasource.testWhileIdle": "true",
"spring.datasource.validationQuery": "SELECT 1",
"spring.jpa.properties.hibernate.dialect": "org.hibernate.dialect.PostgreSQLDialect",
"redis.server": "redis",
"redis.port": "6379",
"signing.key": "345345fsdfsf5345",
"spring.datasource.password": "p0stgr#s"
}
}
]
}
my build script:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.3.1.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
}
group = "com.matches"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "Hoxton.SR6"
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.cloud:spring-cloud-config-server")
implementation("org.springframework.cloud:spring-cloud-starter-config")
implementation("org.springframework.cloud:spring-cloud-starter-eureka")
implementation("org.springframework.boot:spring-boot-starter-actuator")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
ConfigserverApplication:
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.config.server.EnableConfigServer
#SpringBootApplication
#EnableConfigServer
class ConfigserverApplication
fun main(args: Array<String>) {
runApplication<ConfigserverApplication>(*args)
}
I can not find out why it alway decrypts the password?
spring-cloud-config-server always decrypt the encrypted message? NO
ConfigClient can also decrypt if we set encrypt to false like this in ConfigServer.
spring:
cloud:
config:
server:
encrypt:
enabled: false
git:
uri: linkToYourURI
And in the ConfigClient use the key for decryption like this.
Remember to put this in bootstrap.yml as for application.yml it will be too late, see this for further clarification.
encrypt:
key: PutYourKeyHere
Related
I want to setup communication between all the services that I created.
When I add cloud config server gradle dependency in my project and run
the project I got this type of issue
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.
Process finished with exit code 1
I have defined everything properly according to my knowledge, But I am not
able to find the issue from the last 2 days .I try myself
these are the files I created in this project
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.4.5"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.32"
kotlin("plugin.spring") version "1.4.32"
}
group = "com.main"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "2020.0.2"
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.cloud:spring-cloud-config-server")
implementation("org.springframework.cloud:spring-cloud-starter-gateway")
implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
ApiGatewayApplication.kt
package com.main.apigateway
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.netflix.eureka.EnableEurekaClient
#SpringBootApplication
#EnableEurekaClient
class ApigatewayApplication
fun main(args: Array<String>) {
runApplication<ApigatewayApplication>(*args)
}
application.yml
server:
port: 8999
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- id: DEPARTMENT-SERVICE
uri: lb://DEPARTMENT-SERVICE
predicates:
- Path=/departments/**
- id: USER-REGISTRATION
uri: lb://USER-REGISTRATION
predicates:
- Path=/users/**
bootsrap.yml
spring:
cloud:
config:
enabled: true
uri: http://localhost:9296
I implementing a microservices using kafka cloud-stream with avro when I put Sleuth dependency the OUTPUT of the Function, the producer couldn't serialize avro.
Dependency in gradle.build:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
dependencies {
classpath("com.commercehub.gradle.plugin:gradle-avro-plugin:0.16.0")
}
}
plugins {
id("org.springframework.boot") version "2.4.2"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.21"
kotlin("plugin.spring") version "1.4.21"
}
apply(plugin = "com.commercehub.gradle.plugin.avro")
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_15
repositories {
mavenCentral()
maven { url = uri("https://packages.confluent.io/maven/") }
}
extra["springCloudVersion"] = "2020.0.1"
dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.cloud:spring-cloud-stream")
implementation("org.springframework.cloud:spring-cloud-starter-stream-kafka")
implementation("org.apache.kafka:kafka-streams")
//if you take off sleuth dependency of the project the AVRO is converted the json
implementation("org.springframework.cloud:spring-cloud-starter-sleuth")
implementation("io.confluent:kafka-avro-serializer:5.5.0")
implementation("org.apache.avro:avro:1.10.0")
implementation("com.github.javafaker:javafaker:1.0.2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "15"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
follows the little AVRO schema that I used:
{
"namespace": "com.example.demo.events",
"type": "record",
"name": "Person",
"fields": [
{
"name": "name",
"type": "string",
"avro.java.string": "String"
}
]
}
The configuration in application.yml:
server.port: 9091
spring:
application.name: demo-processor
cloud:
stream:
function:
definition: transform
bindings:
transform-in-0:
destination: topic-a
contentType: application/*+avro
group: 'process-uppercase'
transform-out-0:
destination: topic-b
contentType: application/*+avro
producer:
useNativeEncoding: true
kafka:
binder:
brokers: localhost:9092
bindings:
transform-in-0:
consumer:
configuration:
schema.registry.url: http://localhost:8081
value.deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
specific.avro.reader: true
transform-out-0:
producer:
configuration:
schema.registry.url: http://localhost:8081
value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
This the code:
package com.example.demo
import com.example.demo.events.Person
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.messaging.Message
import org.springframework.messaging.support.MessageBuilder
import java.util.function.Function
#SpringBootApplication
class DemoProcessorApplication {
//this function work very well without Sleuth dependency
#Bean
fun transform() = Function<Message<Person>, Message<Person>> {
var person = it.payload
var name = person.getName()
person.setName(name.toUpperCase())
println("Transform ${name} to ${name.toUpperCase()}")
MessageBuilder.withPayload(person).build()
}
}
fun main(args: Array<String>) {
runApplication<DemoProcessorApplication>(*args)
}
I thank you for your help!
How can we enable support for the spring security kotlin DSL?
As you can see from the Screenshot of the IDE (IntelliJ), the DSL is not available:
This is the full SecurityConfig.kt file:
package com.example.backend.core
import org.springframework.context.annotation.Bean
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity
import org.springframework.security.config.web.server.ServerHttpSecurity
import org.springframework.security.web.server.SecurityWebFilterChain
#EnableWebFluxSecurity
class SecurityConfig {
#Bean
fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain? {
return http {
csrf { disable() }
formLogin { disable() }
httpBasic { disable() }
// ...
}
}
}
This is our build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val springBootVersion = "2.4.2"
plugins {
id("org.springframework.boot") version "2.4.2"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.21"
kotlin("plugin.spring") version "1.4.21"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.flywaydb:flyway-core")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("io.micrometer:micrometer-registry-prometheus")
runtimeOnly("org.postgresql:postgresql")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
testImplementation("org.springframework.security:spring-security-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
And this is the intellij version:
IntelliJ IDEA 2020.3 (Community Edition)
Build #IC-203.5981.155, built on November 30, 2020
Runtime version: 11.0.9+11-b1145.21 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.4.0-64-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 12
Registry: compiler.automake.allow.when.app.running=true
Non-Bundled Plugins: Key Promoter X, Dart, io.flutter, Lombook Plugin, org.jetbrains.kotlin
Current Desktop: X-Cinnamon
Do we miss some dependency? Does it require any specific intellij setup?
You need to manually import the ServerHttpSecurity invoke.
import org.springframework.security.config.web.server.invoke
Because of this Kotlin issue in 1.4, the IDE does not suggest it to you as it should.
This is scheduled to be fixed in Kotlin 1.4.30.
I noticed your question was regarding WebFlux, but just complementing #Eleftheria's answer.
For WebMvc folks you should import:
import org.springframework.security.config.web.servlet.invoke
(servlet vs server)
What worked for me was to explicitly call the .invoke method on the HttpSecurity object:
http.invoke {
csrf { disable }
}
which will force my IDE (I'm using IntelliJ) to import the .invoke.
This DSL is built in starting since Spring Security 5.3 version. For example the org.springframework.security:spring-security-config:5.3.4.RELEASE library has it: org.springframework.security.config.web.servlet.HttpSecurityDsl#csrf And for example the
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.3.RELEASE'
library will contain it.
I am unable to properly inject an #Value application property in my Kotlin Spring Boot application. The property as defined in my application.yml file, and subsequently referenced in an additional-spring-configuration-metadata.json file (under resources -> META-INF), is not properly being added to the bean expression context. Using IntelliJ version 2020.2.1, when I hover over the property, I see a Cannot resolve configuration property error. Attempting to run the application (with the configuration property value construction-injected into a class) leads to a Unsatisfied dependency expressed through constructor parameter error.
build.gradle.kts
plugins {
id("org.springframework.boot") version "2.3.3.RELEASE"
id("io.spring.dependency-management") version "1.0.10.RELEASE"
kotlin("jvm") version "1.3.72"
kotlin("plugin.spring") version "1.3.72"
}
group = "com.myProject"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "Hoxton.SR8"
dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.springframework.boot:spring-boot-configuration-processor:2.3.3.RELEASE")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("io.projectreactor:reactor-test")
}
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("com.google.cloud.tools:appengine-gradle-plugin:2.2.0")
}
}
apply(plugin = "com.google.cloud.tools.appengine")
configure<com.google.cloud.tools.gradle.appengine.appyaml.AppEngineAppYamlExtension> {
deploy {
projectId = "my-cloud-project"
version = "GCLOUD_CONFIG"
}
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
Error Message
Spring error modal
additional-spring-configuration-metadata.json
{
"properties": [
{
"name": "otherApi.baseUrl",
"type": "java.lang.String",
"description": "Description for otherApi.baseUrl."
}
]
}
I've added annotation processing dependencies, invalidated caches and restarted, and played around with Kotlin specific annotation processors (kapt). I've also followed the instructions here: https://www.jetbrains.com/help/idea/annotation-processors-support.html
What am I missing? Any and all help would be appreciated. Thanks!
you need to declare the below as as annoatationProcessor
implementation("org.springframework.boot:spring-boot-configuration-processor:2.3.3.RELEASE")
to
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor:2.3.3.RELEASE")
If your application.yml (or application.properties) looks like this:
spring:
datasource:
username: postgres
password: postgres
url: jdbc:postgresql://localhost:5433/company
driver-class-name: org.postgresql.Driver
then try to rewrite each property to full-name format for every property:
spring.datasource.username: postgres
spring.datasource.password: postgres
spring.datasource.url: jdbc:postgresql://localhost:5433/company
spring.datasource.driver-class-name: org.postgresql.Driver
I'm new at spring boot with kotlin.
I have error when application start up.
I had been seeking various solutions in the other answers in Stackoverflow.
But no answers gave me no solutions.
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
My application.properties configuration is following.
spring.datasource.url=jdbc:mysql://localhost/db_name
spring.datasource.username=db_user
spring.datasource.password=db_pass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
And build.gradle.kts is following.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.2.0.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
war
kotlin("jvm") version "1.3.50"
kotlin("plugin.spring") version "1.3.50"
kotlin("plugin.jpa") version "1.3.50"
}
group = "jp.co.blowfish.springboot"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
val developmentOnly by configurations.creating
configurations {
runtimeClasspath {
extendsFrom(developmentOnly)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("mysql:mysql-connector-java")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
I have no idea what is wrong.
It is missing the port of Mysql by default is 3306
spring.datasource.url=jdbc:mysql://localhost:3306/db_name`
or application.properties is in resources folder.