Eureka Server Error EurekaClientAutoConfiguration - spring-boot

Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.env.ConfigurableEnvironment' available: expected at least 1 bean which qualifies as autowire candidate.
Eureka error screenshot
build.gradle
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
springCloudVersion = 'Finchley.RC2'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.ragavan'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone" }
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
runtime('org.springframework.boot:spring-boot-devtools')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
Application
package com.ragavan.discovery;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
#SpringBootApplication
#EnableEurekaServer
public class DiscoveryServerApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryServerApplication.class, args);
}
}

I also faced the same issue :
"No qualifying bean of type'org.springframework.core.env.ConfigurableEnvironment'"
I have used STS + maven in a spring boot project so updating the project with "Force update with snapshot release" will resolve the issue.
Also check if the port is not already in use
In application.properties
spring.application.name=server
server.port=8761
The server will start on port as shown below:

Same issue was coming with 2.1.4.RELEASE also. but it resolved with 2.1.5.RELEASE.

Related

spring-cloud-stream sample projects raises NoSuchBeanDefinitionException of KafkaStreamsFunctionProcessor

I'm trying to touch spring-cloud-stream, and creating a sample project of the official blog.
Implementation is totally same as the article.
#SpringBootApplication
public class SimpleConsumerApplication {
#Bean
public java.util.function.Consumer<KStream<String, String>> process() {
return input ->
input.foreach((key, value) -> {
System.out.println("Key: " + key + " Value: " + value);
});
}
}
I've selected Cloud Stream and Spring for Apache Kafka Stream on Spring initializr, and added ShadowJar. Now my build.gradle is like this.
plugins {
id 'org.springframework.boot' version '2.4.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'com.github.johnrengelman.shadow' version '6.1.0'
}
group = 'com.lipsum'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
jar {
manifest {
attributes('Main-Class': 'com.lipsum.kafkastream.KafkastreamApplication')
}
}
shadowJar {
archiveBaseName.set('kafka-stream-practice')
archiveClassifier.set('')
archiveVersion.set('')
}
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2020.0.2")
}
dependencies {
implementation 'org.apache.kafka:kafka-streams'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka-streams'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
I execute the uber jar, but springboot application fails to recognize the bean.
$ java -jar kafka-stream-practice.jar --spring.cloud.stream.bindings.process-in-0.destination=kafka-stream-practice
...
22:47:21.162 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'kafkaStreamsFunctionProcessorInvoker' defined in class path resource [org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsFunctionAutoConfiguration.class]: Unsatisfied dependency expressed through method 'kafkaStreamsFunctionProcessorInvoker' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsFunctionProcessor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsFunctionProcessor' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
I don't think the implementation has any problems. Do I miss some dependencies?
I tried a quick maven project from the initialize and it starts fine. There was a known bug on the last release (3.0.11) which was fixed since then on the snapshot. You can fix the issue by adding the boot actuator dependency to the project or by upgrading the binder to the latest snapshot. Could you try the maven approach? If the problem still persists, please share a reproducible sample, and then we will take a look.
It works after removing shadowJar and instead uses bootJar task of Spring Boot Gradle plugin.

Spring framework import failed

I am starting on Spring and learning its foundations. I created a project in intellij
It was giving an error stating that web cannot be imported.
so i guessed it must have been . my gradle build file which does not have web
I tried to import in manually via the build.gradle file as below but it throws me an error saying it cannot be found.
WHat am i doing wrong and how can i resolve this?
plugins {
id 'org.springframework.boot' version '2.2.2.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'io.codementor.gtommee'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
any help?
You are missing the spring-boot-starter-web dependency in your build.gradle file.
To get started, have a look at https://start.spring.io/

org.dozer.MappingException: No read or write method found for field (metaClass) in class

I am getting this error when i run my spring boot Application.
Can anyone tell me how to fix it?
my SpringBoot project is based on Groovy and Gradle.
the error massage is like below
16:18:37.215 [http-nio-9092-exec-5] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet]
- Servlet.service() for servlet [dispatcherServlet] in context with path []
threw exception [Request processing failed; nested exception is
org.codehaus.groovy.runtime.typehandling.GroovyCastException:
Cannot cast object 'org.dozer.MappingException:
No read or write method found for field (metaClass) in class (class com.myapp.Orders)'
with class 'org.dozer.MappingException' to class 'java.util.Map'] with root cause
I have no metaClass field in class(com.myapp.Orders).
The class(com.myapp.Orders.groovy) is like below
import lombok.Getter
import lombok.Setter
#Getter
#Setter
class Orders {
long orderId
String kNo
String sOrderCode
int orderStatus
String deliveryTypeCode
String receiverFullName
Date orderAt
}
the destination class(com.myapp.AfOrders.groovy) is like below
import lombok.Getter
import lombok.Setter
#Getter
#Setter
class AfOrders {
String kNo
String sOrderCode
int orderStatus
String deliveryTypeCode
String receiverFullName
Date orderAt
String fType
}
my build.gradle is like below
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url 'http://jcenter.bintray.com' }
}
dependencies {
classpath("io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE")
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("mysql:mysql-connector-java:5.1.45")
classpath ("org.junit.platform:junit-platform-gradle-plugin:1.1.0")
}
}
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.junit.platform.gradle.plugin'
group = 'com.myapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-webflux')
compile('org.springframework.boot:spring-boot-starter-security')
testCompile('org.springframework.security:spring-security-test')
compile('org.flywaydb:flyway-core')
compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.codehaus.groovy:groovy')
runtime('mysql:mysql-connector-java')
compileOnly('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('mysql:mysql-connector-java:5.1.45')
runtime('mysql:mysql-connector-java:5.1.45')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.1')
compile('org.hibernate:hibernate-validator:6.0.8.Final')
compile('net.sf.dozer:dozer:5.5.1')
compile('net.sf.dozer:dozer-spring:5.5.1')
}
my config file is below
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<mapping map-null="false">
<class-a>com.myapp.Orders</class-a>
<class-b>com.myapp.AfOrders</class-b>
<field-exclude type="one-way">
<a>metaClass</a>
<b>metaClass</b>
</field-exclude>
</mapping>
</mappings>
I removed "one-way", it works!

org.springframework.boot.context.embedded does not exist - Gradle build Spring Boot Jetty

I am trying to replace Tomcat with Jetty, as my embedded servlet container. And then need to use EmbeddedServletContainerCustomizer() to configure redirecting requests at port 80 to port 443 (HTTPS). But I am stuck at the very beginning with these gradlew build errors:
RedirectHttpToHttpsOnJettyConfig.java:7: error: package org.springframework.boot.context.embedded does not exist
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
RedirectHttpToHttpsOnJettyConfig.java:8: error: package org.springframework.boot.context.embedded does not exist
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
RedirectHttpToHttpsOnJettyConfig.java:9: error: package org.springframework.boot.context.embedded.jetty does not exist
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
RedirectHttpToHttpsOnJettyConfig.java:10: error: package org.springframework.boot.context.embedded.jetty does not exist
import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer;
...
Here's my build.gradle:
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
ext['thymeleaf.version'] = '3.0.9.RELEASE'
war {
baseName = 'reachout'
version = '0.0.2'
}
compileJava {
options.warnings = true
options.debug = true
options.compilerArgs += ["-Xlint:deprecation"]
}
sourceSets {
main {
java {
exclude '**/RedirectHttpToHttpsOnTomcatConfig.java'
}
}
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity4')
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("com.h2database:h2")
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
Any pointers are much appreciated.
Duplicate. See
Spring Boot 2.0.0.M1: Where is the package org.springframework.boot.context.embed?
Here is the relevant spring commit
https://github.com/spring-projects/spring-boot/commit/67556ba8eaf22a352b03fe197a0c452f695835a6

Unable to inject properties into a class in Spring boot sub module added as a jar in the war

I have a spring boot project with multiple modules which have to be deployed separately. Want to utilize common modules like model,dao and utilities between the projects.
When I had a single project, I was able to get the mongodb related properties loaded for MongoDBConfiguration class.
But when I have dao as a separate module, on server startup spring complains that it cannot resolve the properties required by MongoDBConfiguration class.
Here is my proj structure:
ExampleProj
dao
common
model
webmodule_x
module_y
module_z
build.gradle
Apart from main build.gradle, i have build.gradle for each module.
My dao module has MongoDBConfiguration class like this:
#Configuration
#PropertySource(value = "classpath:/application.properties")
#EnableMongoRepositories(basePackages="com.abc.xyz.dao.repositories*" )
public class MongoDBConfiguration {
#Value( "${mongo.host:abc12345.abc.com}" ) private String mongoHost;
#Value( "${mongodb.name}" ) private String mongodbName;
....
}
Tried different configurations but have the same problem.
My webmodule_x has spring boot starter class like this:
#PropertySource(value={"classpath:application.properties",
"file:${externalDirectory}/webmodule_x/conf/application.properties"
} ,
ignoreResourceNotFound = false)
#ComponentScan("com.abc.xyz")
#Configuration
#EnableAutoConfiguration
#EnableMongoRepositories(basePackages="com.abc.xyz.dao*" )
#Import(MongoDBConfiguration.class)
public class SpringBootStarter {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(SpringBootStarter.class, args);
}
}
Somehow ${mongodb.name} property is not getting initialized.
This is the error I get:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'mongodb.name' in string value "${mongodb.name}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:801) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:955) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
... 86 common frames omitted
This is my build.gradle in webmodule_x like this:
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'idea'
def tomcat_home='/usr/local/apache-tomcat-7.0.55'
sourceCompatibility = 1.7
buildscript {
repositories {
maven { url "http://mavencentral.it.abc.com:8084/nexus/content/groups/xyz" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
systemProperties = System.properties
}
tasks.withType(Test) {
// get System properties needed for tests
systemProperties['externalDirectory'] =
System.getProperty("externalDirectory", "/opt/app/test")
println 'externalDirectory for tests is ' +
systemProperties['externalDirectory']
}
repositories {
maven { url "http://mavencentral.it.abc.com:8084/nexus/content/groups/xyz" }
}
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integration-test/java')
}
resources.srcDir file('src/integration-test/resources')
}
}
configurations{
integrationTestCompile.extendsFrom compile, testCompile
integrationTestRuntime.extendsFrom runtime, testRuntime
providedRuntime
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework:spring-webmvc')
compile project(':common')
compile project(':model')
compile project(':dao')
testCompile('junit:junit','org.hamcrest:hamcrest-library','org.mockito:mockito-core')
testCompile('junit:junit','org.hamcrest:hamcrest-library','org.springframework.boot:spring-boot-starter-test',
'org.mockito:mockito-core', 'org.skyscreamer:jsonassert:1.2.3')
integrationTestCompile('junit:junit','org.hamcrest:hamcrest-library','org.springframework.boot:spring-boot-starter-test',
'org.mockito:mockito-core', 'org.skyscreamer:jsonassert:1.2.3')
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}
task integrationTest(type: Test) {
description = 'Runs the integration tests.'
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
outputs.upToDateWhen { false }
}
// logback(slf4j) commons-logging
[configurations.runtime, configurations.default]*.exclude(module: 'commons-logging')
jar.enabled = true
bootRepackage.enabled = true
My dao build.gradle:
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
sourceCompatibility = 1.7
version = '1.0'
group = 'com.abc.xyz.dao'
version = '0.0.1-SNAPSHOT'
buildscript {
repositories {
maven { url "http://mavencentral.abc.com:8084/nexus/content/groups/xyz" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
configurations{
providedRuntime
}
repositories {
maven { url "http://mavencentral.abc.com:8084/nexus/content/groups/xyz" }
}
dependencies {
compile 'org.springframework.data:spring-data-mongodb'
compile project(':model')
compile 'org.springframework:spring-context'
testCompile('junit:junit','org.hamcrest:hamcrest-library','org.mockito:mockito-core',
'org.mockito:mockito-core', 'org.skyscreamer:jsonassert:1.2.3', 'org.springframework.boot:spring-boot-starter-test',
'org.springframework:spring-webmvc','org.springframework.boot:spring-boot-starter-web', 'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.46.4')
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
jar.enabled = false
bootRepackage.enabled = false
Googled a lot but no luck yet. I get this error both with bootRun and with war deployment into tomcat.
Please let me know how to load properties before an injected bean in a dendent jar class is initialized.
I'm sure you have already checked this but perhaps your keys in the prop file are incorrect?
From your code, I see mongo.host and then mongodb.name
Perhaps the "db" is not in your props?

Resources