How to use jaas configuration in spring-cloud-stream-binder-kafka-streams - spring

I followed this example to create an authentication in my broker kafka, however there are two differences for my project
I use kafka streams binder, while in the example kafka binder is
used.
I only have one broker, while in the example two brokers are
used.
When I run my application it returns the following error:
https://gist.github.com/JacsonF/7363e8d7f4f07a5bc77c28fb1e882674
My function:
#Bean
public Function<KStream<Object, String>, KStream<?, String>[]> receive() {
Predicate<Object, String> isCompensado = (k, v) -> v.contains("XPTO");
Predicate<Object, String> isntCompensado = (k, v) -> !v.contains("XPTO");
return input -> input.branch(isCompensado, isntCompensado);
}
I would like to use only the properties of my application to authenticate, without an external file, just like in the example.
How can I do this?
application.yml

There was an issue with the way JAAS configuration was processed in Kafka Streams binder for Spring Cloud Stream. See this issue for more details. This is fixed now. Make sure that you are using version 3.1.4-SNAPSHOT. Here is a sample application that verifies this.
Update
The Kafka binders for Spring Cloud Stream have been released, version 3.1.4 has the fix.
If you're using spring-cloud-dependencies in your pom to manage dependencies, update it to (at least) version 2020.0.4
For example:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2020.0.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

This works fine for me:
spring.kafka.jaas.enabled=true
spring.kafka.properties.security.protocol=SASL_SSL
spring.kafka.properties.sasl.mechanism=PLAIN
spring.kafka.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="username" password="password";
Output:
2021-05-18 18:50:56.505 INFO 75288 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Creating binder: ktable
2021-05-18 18:50:56.595 INFO 75288 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Caching the binder: ktable
2021-05-18 18:50:56.596 INFO 75288 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Retrieving cached binder: ktable
2021-05-18 18:50:56.722 INFO 75288 --- [ main] o.a.k.clients.admin.AdminClientConfig : AdminClientConfig values:
............ (property)=(value) ............
sasl.mechanism = PLAIN
security.protocol = SASL_SSL
............ (property)=(value) ............
2021-05-18 18:50:56.960 INFO 75288 --- [ main] o.a.k.c.s.authenticator.AbstractLogin : Successfully logged in.
2021-05-18 18:50:57.131 WARN 75288 --- [ main] o.a.k.clients.admin.AdminClientConfig : The configuration 'sasl.jaas.config' was supplied but isn't a known config.
2021-05-18 18:50:57.134 INFO 75288 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.6.0
2021-05-18 12:46:31.423 INFO 74020 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: 62abe01bee039651
2021-05-18 12:46:31.423 INFO 74020 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1621367191408
2021-05-18 12:46:31.423 INFO 74020 --- [ main] o.s.c.s.b.k.p.KafkaTopicProvisioner : Auto creation of topics is disabled.
2021-05-18 12:46:31.456 INFO 74020 --- [ main] org.apache.kafka.streams.StreamsConfig : StreamsConfig values:
I tried the following but not working for me:
https://github.com/spring-cloud/spring-cloud-stream-binder-kafka#using-spring-boot-properties
Using the properties from the above link to set the same values as the first way will have the following error:
2021-05-18 18:59:44.140 INFO 73444 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Creating binder: ktable
2021-05-18 18:59:44.231 INFO 73444 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Caching the binder: ktable
2021-05-18 18:59:44.232 INFO 73444 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Retrieving cached binder: ktable
2021-05-18 18:59:44.352 INFO 73444 --- [ main] o.a.k.clients.admin.AdminClientConfig : AdminClientConfig values:
............ (property)=(value) .............
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
............ (property)=(value) ............
2021-05-18 18:59:44.596 INFO 73444 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.6.0
2021-05-18 18:59:44.597 INFO 73444 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: 62abe01bee039651
2021-05-18 18:59:44.597 INFO 73444 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1621389584594
2021-05-18 18:59:44.599 INFO 73444 --- [ main] o.s.c.s.b.k.p.KafkaTopicProvisioner : Auto creation of topics is disabled.
2021-05-18 18:59:44.611 INFO 73444 --- [| adminclient-1] o.a.k.c.a.i.AdminMetadataManager : [AdminClient clientId=adminclient-1] Metadata update failed
org.apache.kafka.common.errors.TimeoutException: Call(callName=fetchMetadata, deadlineMs=1621389614599, tries=1, nextAllowedTryMs=-9223372036854775709) timed out at 9223372036854775807 after 1 attempt(s)
Caused by: org.apache.kafka.common.errors.TimeoutException: Timed out waiting to send the call.
From the logging, you can see that the second way is NOT using the values you provided and there is no "Successfully logged in".
By the way, I am using the following dependencies:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-kafka-streams</artifactId>
<version>3.1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<version>3.1.3-SNAPSHOT</version>
</dependency>
and the following repositories:
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/libs-milestone-local</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>confluent</id>
<url>https://packages.confluent.io/maven/</url>
</repository>
</repositories>

Related

Spring Cloud Config Client Located Server: properties not loaded

I am sure this is some kind of boot/cloud version dependency issue but I can't figure out the combination of dependencies and property values.
Config Servers starts and properties are available in browser
localhost:8888/master/ucdp-ingest
localhost:8888/master/ucdp-ingest-dev
$ java --version
openjdk 11.0.14.1 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)
Therefore according to 2021-0-3 Availability and the java version we use, went with
Spring Boot: 2.7.6
Spring Cloud: 2021.0.3
Client pom
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.6</version>
<relativePath/>
</parent>
<properties>
<aws-sdk.version>1.12.368</aws-sdk.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<jacoco.version>0.8.8</jacoco.version>
<jasypt-spring-boot.version>3.0.5</jasypt-spring-boot.version>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<spring-cloud.version>2021.0.3</spring-cloud.version>
<spring-cloud-stream-kinesis-binder.version>2.2.0</spring-cloud-stream-kinesis-binder.version>
<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
<swagger-maven-plugin.version>2.1.6</swagger-maven-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
Note no "spring-cloud-starter-bootstrap" per documentation.
Interestingly "spring.profiles.active" shows deprecated.
However, according to Spring 2.4 docs it should be spring.config.activate.on-profile. This doesn't resolve as system property.
-Dspring.config.activate.on-profile=dev
2022-12-23 15:28:51.358 INFO 36316 --- [ main] c.b.u.ucdp.ingest.UcdpIngestApplication : No active profile set, falling back to 1 default profile: "default"
Client: application.yml
spring:
application:
name: ucdp-ingest
cloud:
config:
name: ${spring.application.name}
uri: http://localhost:8888
username: ----------
password: ---------
request-connect-timeout: 3000
request-read-timeout: 3000
retry:
initial-interval: 1000
max-attempts: 6
label: master
fail-fast: true
config:
import: "configserver:"
server:
port: 8300
servlet:
context-path: /${spring.application.name}
# Actuator
management:
#opt-in use enabled-by-default: false then enable what you want. default = true
enabled-by-default: true
server:
port: ${server.port}
endpoints:
web:
base-path: ${server.servlet.context-path}
exposure:
include: "*"
endpoint:
env:
enabled: true
health:
show-details: always
enabled: true
info:
enabled: true
# shutdown:
# enabled: true
#OpenAPI
springdoc:
api-docs:
path: /docs/api-docs
version: openapi_3_1
swagger-ui:
path: /docs/swagger-ui
paths-to-match: /**
REMOTE application-ucdp-ingest.yml
app:
ucdp:
url: https://ucdpapi.pcr.uu.se/api
connect-timeout-millis: 2000
read-timeout-seconds: 2000
ged:
job:
enabled: true
cron: "20 49 11 * * ?"
#Max page size is 1000
pageSize: 1000
uri: /gedevents/21.1
REMOTE application-ucdp-ingest-dev.yml
contains mongo and aws connection properties. Mongo also failed to connect because properties were not loaded remotely.
LOGS: Note I am passing profile as system property.
+ /c/sfw/java/jdk11.0.14_10/bin/java -Dspring.config.activate.on-profile=dev -Dlogging.config=/c/projects/ucdp-ingest/ucdp-ingest-app/config/logback.xml -jar /c/projects/ucdp-ingest/ucdp-ingest-app/target/ucdp-ingest-app-0.0.1-SNAPSHOT.jar
2022-12-23 15:30:50.081 INFO 20496 --- [ main] c.b.u.ucdp.ingest.UcdpIngestApplication : Starting UcdpIngestApplication v0.0.1-SNAPSHOT using Java 11.0.14.1 on BRANDA-BSTAQ-PC with PID 20496 (C:\projects\ucdp-ingest\ucdp-ingest-app\target\ucdp-ingest-app-0.0.1-SNAPSHOT.jar started by BruceRandall in C:\projects\ucdp-ingest\ucdp-ingest-app)
2022-12-23 15:30:50.086 INFO 20496 --- [ main] c.b.u.ucdp.ingest.UcdpIngestApplication : The following 1 profile is active: "dev"
2022-12-23 15:30:50.136 INFO 20496 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : http://localhost:8888
2022-12-23 15:30:50.137 INFO 20496 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Located environment: name=ucdp-ingest, profiles=[dev], label=master, version=7102644c36175df62e3a3952793021cdf730583a, state=null
2022-12-23 15:30:51.495 INFO 20496 --- [ main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
2022-12-23 15:30:51.496 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource configurationProperties [class org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource
2022-12-23 15:30:51.498 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletConfigInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
2022-12-23 15:30:51.498 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Skipping PropertySource servletContextInitParams [class org.springframework.core.env.PropertySource$StubPropertySource
2022-12-23 15:30:51.499 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.499 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource cachedrandom [org.springframework.cloud.util.random.CachedRandomPropertySource] to EncryptablePropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource springCloudClientHostInfo [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource configClient [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.500 INFO 20496 --- [ main] c.u.j.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'file [config\application.yml]' via location 'optional:file:./config/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-23 15:30:51.664 INFO 20496 --- [ main] c.u.j.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
2022-12-23 15:30:51.673 INFO 20496 --- [ main] c.u.j.r.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
2022-12-23 15:30:51.675 INFO 20496 --- [ main] c.u.j.d.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
2022-12-23 15:30:52.246 INFO 20496 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8300 (http)
2022-12-23 15:30:52.256 INFO 20496 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-23 15:30:52.256 INFO 20496 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.69]
2022-12-23 15:30:52.351 INFO 20496 --- [ main] o.a.c.c.C.[.[localhost].[/ucdp-ingest] : Initializing Spring embedded WebApplicationContext
2022-12-23 15:30:52.351 INFO 20496 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2212 ms
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gedJob' defined in URL [jar:file:/C:/projects/ucdp-ingest/ucdp-ingest-app/target/ucdp-ingest-app-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/com/bar/udl/ucdp/ingest/service/impl/GedJob.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid #Scheduled method 'executeJob':
Could not resolve placeholder 'app.ged.job.cron' in value "${app.ged.job.cron}"
ConfigServerConfigDataLoader : Located environment: name=ucdp-ingest, profiles=[dev], label=master, version=7102644c36175df62e3a3952793021cdf730583a, state=null
Could not resolve placeholder 'app.ged.job.cron' in value "${app.ged.job.cron}"
Unfortunately, ConfigServerConfigDataLoader doesn't give you a complete URL
Configuration Server Endpoint
http://localhost:8888/master/ucdp-ingest
{
"name": "master",
"profiles": [
"ucdp-ingest"
],
"label": null,
"version": "155b907870c49c194dee1f1b6d94be768ce043ec",
"state": null,
"propertySources": [
{
"name": "C:\\\\projects\\\\udl-app-config/file:C:\\Users\\BRUCER~1\\AppData\\Local\\Temp\\config-repo-1334124828626900950\\application-ucdp-ingest.yml",
"source": {
"app.ucdp.url": "https://ucdpapi.pcr.uu.se/api",
"app.ucdp.connect-timeout-millis": 2000,
"app.ucdp.read-timeout-seconds": 2000,
"app.ged.job.enabled": true,
"app.ged.job.cron": "20 49 11 * * ?",
"app.ged.pageSize": 1000,
"app.ged.uri": "/gedevents/21.1",
}
}
]
Reverted back to boot 2.4.3, cloud 2020.0.3 but will be working back up to boot 2.7.6 cloud 2021.0.3.
The main issue was incorrectly interpreting the specification for the naming convention for property files. I noticed when querying the configuration server the name was the branch and the profile was the application name. Hence the reason I could only pull properties with localhost:8888/master/app-name-profile
Once I removed application from my file names in the git repository to ${spring.application.name}-profile I was able to query the server correctly and
the client was able to connect and load properties.
My last issue is I can't pass the profile in as a system property -Dspring.profiles.active=dev resolves to default when the bean access the Config Server.

Spring boot does not automatically create database tables on Mysql

First I already went over some solution on stacks but they did not work. I make a very basic/learning app on spring / mysql, no tables joining for the moment. The problem is tables are not creating on mysql, while everything is working. I copy my code hereunder.
Thanks in advance for the help
Console:
2021-06-15 11:25:07.895 INFO 8464 --- [ main]
c.j.v.VotingsystemApplication : Starting
VotingsystemApplication using Java 15.0.2 on LAPTOP-BQ48GM36 with PID
8464 (C:\Users\The Kash\Downloads\votingsystem\target\classes started
by The Kash in C:\Users\The Kash\Downloads\votingsystem)
2021-06-15 11:25:07.898 INFO 8464 --- [ main]
c.j.v.VotingsystemApplication : No active profile set,
falling back to default profiles: default
2021-06-15 11:25:08.734 INFO 8464 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules
found, entering strict repository configuration mode!
2021-06-15 11:25:08.736 INFO 8464 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
JDBC repositories in DEFAULT mode.
2021-06-15 11:25:08.749 INFO 8464 --- [ main] .s.d.
r.c.RepositoryConfigurationDelegate : Finished Spring Data repository
scanning in 6 ms. Found 0 JDBC repository interfaces.
2021-06-15 11:25:08.760 INFO 8464 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules
found, entering strict repository configuration mode!
2021-06-15 11:25:08.762 INFO 8464 --- [ main] .s.d.
r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA
repositories in DEFAULT mode.
2021-06-15 11:25:08.769 INFO 8464 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data
repository scanning in 1 ms. Found 0 JPA repository interfaces.
2021-06-15 11:25:09.628 INFO 8464 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with
port(s): 8080 (http)
2021-06-15 11:25:09.640 INFO 8464 --- [ main]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-06-15 11:25:09.640 INFO 8464 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine:
[Apache Tomcat/9.0.46]
2021-06-15 11:25:09.776 INFO 8464 --- [ main] o.a.c.c.C.
[Tomcat].[localhost].[/] : Initializing Spring embedded
WebApplicationContext
2021-06-15 11:25:09.776 INFO 8464 --- [ main]
w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext:
initialization completed in 1808 ms
2021-06-15 11:25:09.924 INFO 8464 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-06-15 11:25:10.415 INFO 8464 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start
completed.
2021-06-15 11:25:10.582 INFO 8464 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [name: default]
2021-06-15 11:25:10.672 INFO 8464 --- [ main]
org.hibernate.Version : HHH000412: Hibernate ORM
core version 5.4.32.Final
2021-06-15 11:25:10.879 INFO 8464 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.1.2.Final}
2021-06-15 11:25:11.018 INFO 8464 --- [ main]
org.hibernate.dialect.Dialect : HHH000400: Using dialect:
org.hibernate.dialect.MySQL5Dialect
2021-06-15 11:25:11.260 INFO 8464 --- [ main]
o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform
implementation:
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-06-15 11:25:11.272 INFO 8464 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default'
2021-06-15 11:25:11.322 WARN 8464 --- [ main]
JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is
enabled by default. Therefore, database queries may be performed during
view rendering. Explicitly configure spring.jpa.open-in-view to disable
this warning
2021-06-15 11:25:11.735 WARN 8464 --- [ main]
ion$DefaultTemplateResolverConfiguration : Cannot find template
location: classpath:/templates/ (please add some templates or check
your Thymeleaf configuration)
2021-06-15 11:25:11.999 INFO 8464 --- [ main] o.s.b.
w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080
(http) with context path ''
2021-06-15 11:25:12.013 INFO 8464 --- [ main]
c.j.v.VotingsystemApplication : Started
VotingsystemApplication
in 4.595 seconds (JVM running for 5.166)
VotingsystemApplication.java (main app)
package com.javaenterprise.votingsystem;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class VotingsystemApplication {
public static void main(String[] args) {
SpringApplication.run(VotingsystemApplication.class, args);
}
}
application.properties
spring.datasource.url=jdbc:mysql://localhost/VotingSystem
spring.datasource.username=root
spring.datasource.password=rooting1
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.dialect =
org.hibernate.dialect.MySQL5Dialect
Citizen.java
package com.javaenterprise.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "citizens")
public class Citizen {
#Id
#Column(name="id")
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
#Column(name = "citizen_name")
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Citizen(Long id, String name) {
super();
this.id = id;
this.name = name;
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-
4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.javaenterprise</groupId>
<artifactId>votingsystem</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>votingsystem</name>
<description>Voting system in sprin</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The main entry point of your application is in the com.javaenterprise.votingsystem package. This means that component and entity scanning will find classes in com.javaenterprise.votingsystem and any of its sub-packages. Your entities are in the com.javaenterprise.entity which isn't covered by this scanning.
You could solve the problem by renaming your com.javaenterprise.entity package to com.javaenterprise.votingsystem.entity. Alternatively, you can use #EntityScan to specify the packages that you want to be scanned for entities.
Use the following property:
spring.datasource.url=jdbc:mysql://localhost:3306/dbname?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto=update
And Second, Please add a default constructor as well.
So ur entity class will become:
package com.javaenterprise.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name = "citizens")
#Data
#AllArgsConstructor
#NoArgsConstructor
public class Citizen {
#Id
#Column(name="id")
private Long id;
#Column(name = "citizen_name")
private String name;
}
Can you try implementing Serializable and add DEFAULT Constructor ?
You can use this in your application.properties file
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root/your username
spring.datasource.password= yourpassword
spring.datasource.url=jdbc:mysql://localhost:3306/kibria
#for mysql dialect
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql = true

Auto queue exchange creation with spring cloud function and rabbitmq

We are creating a rabbitMq consumer using the new spring cloud function library.
However we find that on startup of the application, we don't see the queues or exchanges create on the rabbitMq instance.
Here is our config.
spring:
cloud:
function:
definition: someReceiver
stream:
binders:
rabbit:
type: rabbit
bindings:
someReceiver-in-0:
consumer:
max-attemps: 1
batch-mode: true
binder: rabbit
destination: someExhange
group: someQueue
default-binder: rabbit
rabbit:
bindings:
someReceiver-in-0:
consumer:
acknowledge-mode: MANUAL
auto-bind-dlq: true
queue-name-group-only: true
exchange-type: topic
max-concurrency: 10
prefetch: 200
enable-batching: true
batch-size: 10
receive-timeout: 200
dlq-dead-letter-exchange:
This is our consumer.
#Bean
public Consumer<Message<Long>> someReceiver() {
return ....
}
In logs we can see :
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel errorChannel
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel nullChannel
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageHandler _org.springframework.integration.errorLogger
o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
o.s.i.channel.PublishSubscribeChannel : Channel 'X' has 1 subscriber(s).
The problem we are having is that no queue or exchange is being created on the rabbitMq broker on application startup.
We were expecting that a queue named someQueue and an exchanged named someExchange should have been created on application startup
Works as designed just directly from https://start.spring.io:
2021-04-19 12:02:07.476 INFO 28260 --- [ main] o.s.c.s.m.DirectWithAttributesChannel : Channel 'application.someReceiver-in-0' has 1 subscriber(s).
2021-04-19 12:02:07.563 INFO 28260 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel errorChannel
2021-04-19 12:02:07.595 INFO 28260 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel nullChannel
2021-04-19 12:02:07.600 INFO 28260 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel someReceiver-in-0
2021-04-19 12:02:07.613 INFO 28260 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Registering MessageHandler _org.springframework.integration.errorLogger
2021-04-19 12:02:07.631 INFO 28260 --- [ main] o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2021-04-19 12:02:07.631 INFO 28260 --- [ main] o.s.i.channel.PublishSubscribeChannel : Channel 'application.errorChannel' has 1 subscriber(s).
2021-04-19 12:02:07.631 INFO 28260 --- [ main] o.s.i.endpoint.EventDrivenConsumer : started bean '_org.springframework.integration.errorLogger'
2021-04-19 12:02:07.632 INFO 28260 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Creating binder: rabbit
2021-04-19 12:02:07.740 INFO 28260 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Caching the binder: rabbit
2021-04-19 12:02:07.740 INFO 28260 --- [ main] o.s.c.s.binder.DefaultBinderFactory : Retrieving cached binder: rabbit
2021-04-19 12:02:07.792 INFO 28260 --- [ main] c.s.b.r.p.RabbitExchangeQueueProvisioner : declaring queue for inbound: someQueue, bound to: someExhange
2021-04-19 12:02:07.793 INFO 28260 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2021-04-19 12:02:07.938 INFO 28260 --- [ main] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#244e619a:0/SimpleConnection#73a0f2b [delegate=amqp://guest#127.0.0.1:5672/, localPort= 51143]
2021-04-19 12:02:07.991 INFO 28260 --- [ main] o.s.c.stream.binder.BinderErrorChannel : Channel 'someQueue.errors' has 1 subscriber(s).
2021-04-19 12:02:07.991 INFO 28260 --- [ main] o.s.c.stream.binder.BinderErrorChannel : Channel 'someQueue.errors' has 2 subscriber(s).
2021-04-19 12:02:08.002 INFO 28260 --- [ main] o.s.i.a.i.AmqpInboundChannelAdapter : started bean 'inbound.someQueue'
2021-04-19 12:02:08.010 INFO 28260 --- [ main] o.s.s.c.s.s.So67160902Application : Started So67160902Application in 1.659 seconds (JVM running for 2.147)
And I see this in the Rabbit MQ Management Console:
You probably miss some dependency or do something else in your configuration to prevent RabbitMQ Binder to do its stuff.
This is my deps, which are in the pom just generated from https://start.spring.io:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<scope>test</scope>
<classifier>test-binder</classifier>
<type>test-jar</type>
</dependency>
</dependencies>

R2dbc and Jdbc Probelm Spring Boot

Hi everyone I wrote a rest api using Spring Boot Webflux
LabelController
#RestController
#RequestMapping("/api/label")
#RequiredArgsConstructor
public class LabelController {
private final LabelService labelService;
#GetMapping
public Flux<LabelEntity> getAllLabels(){
return labelService.getAll();
}
LabelService
#Service
#RequiredArgsConstructor
public class LabelService {
private final LabelRepository labelRepository;
public Flux<LabelEntity> getAll() {
return labelRepository.findAll();
}
LabelRespository
#Repository
public interface LabelRepository extends ReactiveCrudRepository<LabelEntity,Integer> {
}
Application.yml
Since I use liquebase in the application yml part, I added jdbc and r2dbc.
spring:
liquibase:
enabled: true
url: jdbc:postgresql://localhost:5432/liquebase
user: postgres
password: 12345
change-log: classpath:db/liquibase/db.changelog-master-main.yml
datasource:
driver-class-name: org.postgresql.Driver
r2dbc:
url: r2dbc:postgresql://localhost:5432/liquebase
username: postgres
password: 12345
pool:
initial-size: 100
max-size: 500
max-idle-time: 30m
validation-query: SELECT 1
server:
port: 8085
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.WebFluxTestCodes</groupId>
<artifactId>WebFluxTestCodes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>WebFluxTestCodes</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.10.3</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
My RestApi Main Class
#SpringBootApplication
#EnableR2dbcRepositories
#ComponentScan("com.WebFluxTestCodes.WebFluxTestCodes.business.*")
public class WebFluxTestCodesApplication {
public static void main(String[] args) {
SpringApplication.run(WebFluxTestCodesApplication.class, args);
}
}
Log my project not problem in project is started
2021-03-15 20:38:12.375 INFO 8692 --- [ restartedMain] c.W.W.WebFluxTestCodesApplication :
Starting WebFluxTestCodesApplication using Java 15.0.1 on WIN-3QMQSJHKUBK with PID 8692
(C:\Users\user\Desktop\TestWebService\WebFluxTestCodes\target\classes started by user in
C:\Users\user\Desktop\TestWebService\WebFluxTestCodes)
2021-03-15 20:38:12.375 INFO 8692 --- [ restartedMain] c.W.W.WebFluxTestCodesApplication :
No active profile set, falling back to default profiles: default
2021-03-15 20:38:13.266 INFO 8692 --- [ restartedMain] o.s.b.devtools.restart.ChangeableUrls :
The Class-Path manifest attribute in C:\Users\user\.m2\repository\org\liquibase\liquibase-
core\3.10.3\liquibase-core-3.10.3.jar referenced one or more files that do not exist:
file:/C:/Users/user/.m2/repository/org/liquibase/liquibase-core/3.10.3/commons-cli-
1.4.jar,file:/C:/Users/user/.m2/repository/org/liquibase/liquibase-core/3.10.3/snakeyaml-
1.24.jar,file:/C:/Users/user/.m2/repository/org/liquibase/liquibase-core/3.10.3/slf4j-api-
1.7.28.jar,file:/C:/Users/user/.m2/repository/org/liquibase/liquibase-core/3.10.3/logback-classic-
1.2.3.jar,file:/C:/Users/user/.m2/repository/org/liquibase/liquibase-core/3.10.3/logback-core-
1.2.3.jar
2021-03-15 20:38:13.266 INFO 8692 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor :
Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-03-15 20:38:13.266 INFO 8692 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor :
For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-03-15 20:38:16.782 INFO 8692 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate :
Multiple Spring Data modules found, entering strict repository configuration mode!
2021-03-15 20:38:16.782 INFO 8692 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate
: Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
2021-03-15 20:38:17.264 INFO 8692 --- [ restartedMain] .RepositoryConfigurationExtensionSupport
: Spring Data R2DBC - Could not safely identify store assignment for repository candidate
interface com.WebFluxTestCodes.WebFluxTestCodes.repository.LabelRepository. If you want this
repository to be a R2DBC repository, consider annotating your entities with one of these
annotations: org.springframework.data.relational.core.mapping.Table (preferred), or consider
extending one of the following types with your repository:
org.springframework.data.r2dbc.repository.R2dbcRepository.
2021-03-15 20:38:17.276 INFO 8692 --- [ restartedMain]
.RepositoryConfigurationExtensionSupport : Spring Data R2DBC - Could not safely identify store
assignment for repository candidate interface
com.WebFluxTestCodes.WebFluxTestCodes.repository.ProjectRepository. If you want this repository
to be a R2DBC repository, consider annotating your entities with one of these annotations:
org.springframework.data.relational.core.mapping.Table (preferred), or consider extending one of
the following types with your repository:
org.springframework.data.r2dbc.repository.R2dbcRepository.
2021-03-15 20:38:17.280 INFO 8692 --- [ restartedMain] .RepositoryConfigurationExtensionSupport
: Spring Data R2DBC - Could not safely identify store assignment for repository candidate
interface com.WebFluxTestCodes.WebFluxTestCodes.repository.TasksRepository. If you want this
repository to be a R2DBC repository, consider annotating your entities with one of these
annotations: org.springframework.data.relational.core.mapping.Table (preferred), or consider
extending one of the following types with your repository:
org.springframework.data.r2dbc.repository.R2dbcRepository.
2021-03-15 20:38:17.284 INFO 8692 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate
: Finished Spring Data repository scanning in 452 ms. Found 0 R2DBC repository interfaces.
2021-03-15 20:38:18.522 INFO 8692 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate
: Multiple Spring Data modules found, entering strict repository configuration mode!
2021-03-15 20:38:18.624 INFO 8692 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate
: Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
2021-03-15 20:38:18.714 INFO 8692 --- [ restartedMain] .RepositoryConfigurationExtensionSupport
: Spring Data R2DBC - Could not safely identify store assignment for repository candidate
interface com.WebFluxTestCodes.WebFluxTestCodes.repository.LabelRepository. If you want this
repository to be a R2DBC repository, consider annotating your entities with one of these
annotations: org.springframework.data.relational.core.mapping.Table (preferred), or consider
extending one of the following types with your repository:
org.springframework.data.r2dbc.repository.R2dbcRepository.
2021-03-15 20:38:18.718 INFO 8692 --- [ restartedMain]
.RepositoryConfigurationExtensionSupport : Spring Data R2DBC - Could not safely identify store
assignment for repository candidate interface
com.WebFluxTestCodes.WebFluxTestCodes.repository.ProjectRepository. If you want this repository
to be a R2DBC repository, consider annotating your entities with one of these annotations:
org.springframework.data.relational.core.mapping.Table (preferred), or consider extending one
of the following types with your repository:
org.springframework.data.r2dbc.repository.R2dbcRepository.
2021-03-15 20:38:18.723 INFO 8692 --- [ restartedMain] .RepositoryConfigurationExtensionSupport
: Spring Data R2DBC - Could not safely identify store assignment for repository candidate
interface com.WebFluxTestCodes.WebFluxTestCodes.repository.TasksRepository. If you want this
repository to be a R2DBC repository, consider annotating your entities with one of these
annotations: org.springframework.data.relational.core.mapping.Table (preferred), or consider
extending one of the following types with your repository:
org.springframework.data.r2dbc.repository.R2dbcRepository.
2021-03-15 20:38:18.724 INFO 8692 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate
: Finished Spring Data repository scanning in 97 ms. Found 0 R2DBC repository interfaces.
2021-03-15 20:38:26.847 INFO 8692 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource
: HikariPool-1 - Starting...
2021-03-15 20:38:28.550 INFO 8692 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource
: HikariPool-1 - Start completed.
2021-03-15 20:38:42.546 INFO 8692 --- [ restartedMain] l.lockservice.StandardLockService
: Successfully acquired change log lock
2021-03-15 20:38:44.908 INFO 8692 --- [ restartedMain] l.c.StandardChangeLogHistoryService
: Reading from public.databasechangelog
2021-03-15 20:38:45.635 INFO 8692 --- [ restartedMain] l.lockservice.StandardLockService :
Successfully released change log lock
2021-03-15 20:38:45.651 INFO 8692 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource :
HikariPool-1 - Shutdown initiated...
2021-03-15 20:38:45.698 INFO 8692 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource
: HikariPool-1 - Shutdown completed.
2021-03-15 20:38:46.773 INFO 8692 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer
: LiveReload server is running on port 35729
2021-03-15 20:38:47.884 INFO 8692 --- [ restartedMain] o.s.b.web.embedded.netty.NettyWebServer :
Netty started on port 8085
2021-03-15 20:38:47.915 INFO 8692 --- [ restartedMain] c.W.W.WebFluxTestCodesApplication
: Started WebFluxTestCodesApplication in 39.523 seconds (JVM running for 45.043)
However, when I send a request using the browser, no request comes to the controllers and the following error occurs in the browser.
This application has no configured error view, so you are seeing this as a fallback.
Mon Mar 15 20:38:51 AZT 2021
[005bd2a6-1] There was an unexpected error (type=Not Found, status=404).
org.springframework.web.server.ResponseStatusException: 404 NOT_FOUND
at
org.springframework.web.reactive.resource.ResourceWebHandler
.lambda$handle$1(ResourceWebHandler.java:378)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ HTTP GET "/all" [ExceptionHandlingWebHandler]
Stack trace:
at
org.springframework.web.reactive.resource
.ResourceWebHandler.lambda$handle$1(ResourceWebHandler.java:378)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)
at reactor.core.publisher.Mono.subscribe(Mono.java:4046)
at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber
.onComplete(FluxSwitchIfEmpty.java:81)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onComplete(MonoFlatMap.java:181)
at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:102)
at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:366)
at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:218)
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:164)
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86)
at reactor.core.publisher.Mono.subscribe(Mono.java:4046)
at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:173)
at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:157)
at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber
.onNext(FluxSwitchIfEmpty.java:73)
at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82)
at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:281)
at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:860)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onNext(FluxMapFuseable.java:127)
at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2397)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.request(FluxMapFuseable.java:169)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2193)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onSubscribe(Operators.java:2067)
at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber
.onSubscribe(FluxMapFuseable.java:96)
at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54)
at reactor.core.publisher.Mono.subscribe(Mono.java:4046)
at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:448)
at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:218)
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:164)
at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52)
at reactor.core.publisher.Mono.subscribe(Mono.java:4046)
at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:173)
at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56)
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64)
at reactor.netty.http.server.HttpServer$HttpServerHandle.onStateChange(HttpServer.java:860)
at reactor.netty.ReactorNetty$CompositeConnectionObserver.onStateChange(ReactorNetty.java:638)
at reactor.netty.transport.ServerTransport$ChildObserver.onStateChange(ServerTransport.java:478)
at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:525)
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:94)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:209)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:832)
Request Controller Project Not Working What is the problem ? it is very important to me Please Help me
My project github link --https://github.com/Z-Farrukzada/Webflux-Reactive-Programming-example

SpringCloud-Finchley.SR2 Eureka register-center page status 404

I imported a springcloud demo , version Finchley.SR2, after starting the application,I couldn't visit Eureka register center page,status 404.
I don't have and controller yet,Only a #SpringBootApplication
Same problem on eclipse and Idea
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Apr 17 10:46:08 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
If I use version Finchley.SR1 with dependency jersey-bundle 1.19, everything is normal.
Here is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>groupId</groupId>
<artifactId>register-center</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>register-center</name>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
here is the starting log that console output:
2019-04-17 10:45:55.070 INFO 6608 --- [ main] c.g.c.h.HubRegisterCenterApplication : No active profile set, falling back to default profiles: default
2019-04-17 10:45:55.930 WARN 6608 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2019-04-17 10:45:56.189 INFO 6608 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=b735a91d-6156-3751-9e56-6f2bcdd0ff57
2019-04-17 10:45:56.294 INFO 6608 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e5276a08] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-17 10:45:56.982 INFO 6608 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8761 (http)
2019-04-17 10:45:57.007 INFO 6608 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-17 10:45:57.007 INFO 6608 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-17 10:45:57.277 INFO 6608 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-17 10:45:57.277 INFO 6608 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2190 ms
2019-04-17 10:45:57.390 WARN 6608 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-04-17 10:45:57.390 INFO 6608 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-04-17 10:45:57.408 INFO 6608 --- [ main] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#4af70944
2019-04-17 10:45:58.631 WARN 6608 --- [ main] o.s.c.n.a.ArchaiusAutoConfiguration : No spring.application.name found, defaulting to 'application'
2019-04-17 10:45:58.632 WARN 6608 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-04-17 10:45:58.632 INFO 6608 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-04-17 10:45:58.854 INFO 6608 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-17 10:45:59.276 WARN 6608 --- [ main] o.s.b.a.f.FreeMarkerAutoConfiguration : Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
2019-04-17 10:45:59.470 INFO 6608 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-04-17 10:45:59.716 INFO 6608 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-04-17 10:45:59.756 INFO 6608 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-04-17 10:45:59.758 INFO 6608 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
2019-04-17 10:45:59.775 INFO 6608 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1555469159773 with initial instances count: 0
2019-04-17 10:45:59.781 INFO 6608 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application UNKNOWN with eureka with status UP
2019-04-17 10:45:59.840 INFO 6608 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8761 (http) with context path ''
2019-04-17 10:45:59.844 INFO 6608 --- [ main] c.g.c.h.HubRegisterCenterApplication : Started HubRegisterCenterApplication in 6.441 seconds (JVM running for 7.261)
2019-04-17 10:46:08.612 INFO 6608 --- [nio-8761-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-17 10:46:08.612 INFO 6608 --- [nio-8761-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-04-17 10:46:08.618 INFO 6608 --- [nio-8761-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms
Here is my application.yml:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
Here is my Application class:
#SpringBootApplication
#EnableEurekaServer
public class HubRegisterCenterApplication {
public static void main(String[] args) {
SpringApplication.run(HubRegisterCenterApplication.class, args);
}
}
Problem solved.
use mvn install command,and I found that there is some problems in maven dependency jar file. delete them and re-download,problem solved
Use application.properties file instead of application.yml file.
like
spring.application.name=cart-service
server.port=8082
It worked for me.

Resources