Spring Boot and Flyway: file location with spring.flyway.locations is ignored - spring-boot

Spring Boot 1.5.11, Flyway 5.0.7 (also tried 5.1.1). The location specification is ignored. What am I missing here?
spring:
profiles: db_h2
datasource:settings
platform: h2
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:log4jdbc:h2:mem:TEST;DB_CLOSE_ON_EXIT=FALSE
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
hikari:
maximum-pool-size: 5
driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
flyway:
locations: classpath:/flyway/h2,classpath:/flyway/common,classpath:/flyway/testdata
h2:
console:
enabled: true
path: /h2
Log excerpt shows that the right profile is picked up but the specified setting is not:
2018-06-05 08:24:48.282 DEBUG 13188 --- [ main] c.c.c.backend.config.Application : Running with Spring Boot v1.5.11.RELEASE, Spring v5.0.5.RELEASE
2018-06-05 08:24:48.282 INFO 13188 --- [ main] c.c.c.backend.config.Application : The following profiles are active: db_h2,logging_normal,http_insecure,credentials_insecure,option_create_sql_script
2018-06-05 08:24:52.240 INFO 13188 --- [ main] o.f.core.internal.util.VersionPrinter : Flyway Community Edition 5.0.7 by Boxfuse
2018-06-05 08:24:52.414 INFO 13188 --- [ main] o.f.c.internal.database.DatabaseFactory : Database: jdbc:h2:mem:TEST (H2 1.4)
2018-06-05 08:24:52.431 DEBUG 13188 --- [ main] jdbc.sqltiming : com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
1. CALL SCHEMA()
{executed in 5 msec}
2018-06-05 08:24:52.445 DEBUG 13188 --- [ main] org.flywaydb.core.Flyway : DDL Transactions Supported: false
2018-06-05 08:24:52.447 DEBUG 13188 --- [ main] org.flywaydb.core.Flyway : Schema: PUBLIC
2018-06-05 08:24:52.452 DEBUG 13188 --- [ main] o.f.core.internal.util.FeatureDetector : Spring Jdbc available: true
2018-06-05 08:24:52.454 DEBUG 13188 --- [ main] o.f.c.i.c.SqlScriptFlywayCallback : Scanning for SQL callbacks ...
2018-06-05 08:24:52.455 DEBUG 13188 --- [ main] o.f.c.i.u.s.classpath.ClassPathScanner : Scanning for classpath resources at 'classpath:db/migration' (Prefix: '', Suffixes: '.sql')
2018-06-05 08:24:52.455 DEBUG 13188 --- [ main] o.f.c.i.u.s.classpath.ClassPathScanner : Determining location urls for classpath:db/migration using ClassLoader sun.misc.Launcher$AppClassLoader#18b4aac2 ...
2018-06-05 08:24:52.506 WARN 13188 --- [ main] o.f.c.i.u.s.classpath.ClassPathScanner : Unable to resolve location classpath:db/migration

From the Spring Boot 1.5 documentation I would say that the correct property name is flyway.locations, without spring prefix. It differs between 1.5 and 2.0 branches.

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 Eureka Client won't connect server

I am making an application with multiple Eureka servers connecting to one Eureka Server. Currently I have two services. The server runs on port 8761, service one runs on 8081 and service two runs on 8082. My first service does connect successfully to the server, however my second service doesn't connect to the server and doesn't give any error messages in the console.
This is from my second service that won't connect:
spring:
application:
name: stock-service
datasource:
url: jdbc:postgresql://localhost:5433/thuusbezorgd
username: postgres
password: secretpassword
driver-class-name: org.postgresql.Driver
jpa:
database-platform: org.hibernate.dialect.PostgresSQLDialect
show-sql: true
jpa:
generate-ddl: true
defer-datasource-initialization: true
hibernate:
ddl-auto: create-drop
sql:
init:
mode: always
server:
port: 8082
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
#SpringBootApplication
#EnableEurekaClient
public class StockServiceApplication {
public static void main(String[] args) {
SpringApplication.run(StockServiceApplication.class, args);
}
}
This is the application.yml from the working service that does connect:
spring:
application:
name: shopping-cart-service
server:
port: 8081
shopping-cart:
redis:
host: localhost
port: 6379
password: ''
memcached:
host: localhost
port: 11211
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
I am getting 0 error messages in my console from Eureka, this is the output of the first service that isn't connecting to the server:
2022-11-29T20:55:10.956+01:00 INFO 8344 --- [ main] c.j.s.StockServiceApplication : Starting StockServiceApplication using Java 18.0.2 with PID 8344 (D:\school\thuusbezorgd-JaimieVos\stock-service\target\classes started by jaimi in D:\school\thuusbezorgd-JaimieVos\stock-service)
2022-11-29T20:55:10.959+01:00 INFO 8344 --- [ main] c.j.s.StockServiceApplication : No active profile set, falling back to 1 default profile: "default"
2022-11-29T20:55:11.424+01:00 INFO 8344 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-11-29T20:55:11.542+01:00 INFO 8344 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 112 ms. Found 2 JPA repository interfaces.
2022-11-29T20:55:11.907+01:00 INFO 8344 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http)
2022-11-29T20:55:11.920+01:00 INFO 8344 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-11-29T20:55:11.920+01:00 INFO 8344 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-11-29T20:55:12.000+01:00 INFO 8344 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-11-29T20:55:12.000+01:00 INFO 8344 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1004 ms
2022-11-29T20:55:12.105+01:00 INFO 8344 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-11-29T20:55:12.141+01:00 INFO 8344 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.5.Final
2022-11-29T20:55:12.260+01:00 WARN 8344 --- [ main] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
2022-11-29T20:55:12.360+01:00 INFO 8344 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-11-29T20:55:12.478+01:00 INFO 8344 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection#1f172892
2022-11-29T20:55:12.479+01:00 INFO 8344 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-11-29T20:55:12.514+01:00 INFO 8344 --- [ main] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-11-29T20:55:13.172+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2022-11-29T20:55:13.173+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "product_ingredient" does not exist, skipping
2022-11-29T20:55:13.174+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2022-11-29T20:55:13.175+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : relation "product_ingredient" does not exist, skipping
2022-11-29T20:55:13.176+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2022-11-29T20:55:13.176+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : table "ingredient" does not exist, skipping
2022-11-29T20:55:13.177+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2022-11-29T20:55:13.178+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : table "product" does not exist, skipping
2022-11-29T20:55:13.179+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 0, SQLState: 00000
2022-11-29T20:55:13.179+01:00 WARN 8344 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : table "product_ingredient" does not exist, skipping
2022-11-29T20:55:13.222+01:00 INFO 8344 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-11-29T20:55:13.228+01:00 INFO 8344 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-11-29T20:55:13.445+01:00 WARN 8344 --- [ 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
2022-11-29T20:55:13.818+01:00 INFO 8344 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8082 (http) with context path ''
2022-11-29T20:55:13.826+01:00 INFO 8344 --- [ main] c.j.s.StockServiceApplication : Started StockServiceApplication in 3.279 seconds (process running for 3.777)
So I am wondering if there is something I am completely missing because I cannot find anything that would cause service 1 not to work but service 2 running absolutely fine. When I visit my first service that doesn't connect to the server from its url itself through localhost:8082 it works fine.
I tried switching the ports but service 1 didn't want to connect with any port.

Spring boot H2 console returns 404

I have a simple Springboot application and it's up running. I am able to call REST endpoints through Postman. However, when I try to access the console using http://localhost:8080/h2 it keeps returning 404.
2020-08-29 08:06:37.577 INFO 6507 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-08-29 08:06:37.644 INFO 6507 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2020-08-29 08:06:37.645 INFO 6507 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-08-29 08:06:37.677 INFO 6507 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-08-29 08:06:37.787 INFO 6507 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-08-29 08:06:38.247 INFO 6507 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-08-29 08:06:38.737 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-08-29 08:06:38.738 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2020-08-29 08:06:38.741 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2020-08-29 08:06:38.813 INFO 6507 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2020-08-29 08:06:38.813 INFO 6507 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2020-08-29 08:06:38.816 INFO 6507 --- [ main] c.v.t.c.m.tenant.discovery.Application : Started Application in 3.4 seconds (JVM running for 3.661)
2020-08-29 08:06:48.527 WARN 6507 --- [ctor-http-nio-2] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/h2]: Response status 404
2020-08-29 08:23:07.301 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Retrograde clock change detected (housekeeper delta=29s626ms), soft-evicting connections from pool.
2020-08-29 08:57:06.586 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=33m59s284ms).
2020-08-29 09:35:49.699 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper
My application.yml file looks like this.
spring:
datasource:
url: jdbc:h2:mem:test
platform: h2
username: sa
password:
driverClassName: org.h2.Driver
hikari:
maximum-pool-size: 50
h2:
console:
enabled: true
path: /h2
settings:
web-allow-others: true
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
server:
port: 8080
As per your logs, I found that, you are using an embedded server, other than tomcat, i.e, spring-boot-starter-reactor-netty that comes along with spring webflux dependency.
H2ConsoleAutoConfiguration will not be executed for spring webflux & netty(reactor based), as H2 console will only be available to servlet based applications. So, you have to configure H2 server manually in this spring boot application, with spring webflux & netty.
Sample H2Server (working code):
package com.example.springbootnettyserver;
import org.h2.tools.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import static org.h2.tools.Server.createWebServer;
#Component
public class H2ServerManual {
Logger log = LoggerFactory.getLogger(H2ServerManual.class);
private Server webServer;
#Value("${h2-server.port}")
Integer h2ConsolePort;
#EventListener(ContextRefreshedEvent.class)
public void start() throws java.sql.SQLException {
log.info("starting h2 console at port "+ h2ConsolePort);
this.webServer = createWebServer("-webPort", h2ConsolePort.toString(),
"-tcpAllowOthers").start();
System.out.println(webServer.getURL());
}
#EventListener(ContextClosedEvent.class)
public void stop() {
log.info("stopping h2 console at port "+h2ConsolePort);
this.webServer.stop();
}
}
Note: org.h2.tools.Server class will be resolved only when h2 dependency is added without scope of runtime. (remove scope element in dependency)
In application.properties, you will add port details for h2 server like
h2-server:
port: 8081
Here, now, the H2 console will be available at http://localhost:8081
Following properties can be removed
# h2:
# console:
# enabled: true
# path: /h2
# settings:
# web-allow-others: true
For Reference: https://github.com/donthadineshkumar/webflux-netty-server-h2-example.git

How to move Zuul gateway configurations to configuration server

I'm starting out with microservices architecture and spring cloud.
I'm trying to get configurations for my Spring Zuul Gateway from the spring configuration server.
I've added below properties in bootstrap.properties file of the gateway service:
spring.application.name=api-gateway
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=dev
Even though these properties work for all other services, for the gateway they do not work.
The annotations I'm using for the gateway are:
#EnableZuulProxy
#EnableDiscoveryClient
#SpringBootApplication
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
The annotation for other services is only:
#SpringBootApplication
My configuration server has a connected git repository with a file: api-gateway-dev.properties
logs of gateway:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:42:39.983 INFO 10340 --- [ restartedMain]
c.nyo.apigateway.ApiGatewayApplication : The following profiles are
active: dev 2020-04-17 21:42:41.926 WARN 10340 --- [ restartedMain]
o.s.boot.actuate.endpoint.EndpointId : Endpoint ID
'service-registry' contains invalid characters, please migrate to a
valid format. 2020-04-17 21:42:41.969 WARN 10340 --- [
restartedMain] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID
'hystrix.stream' contains invalid characters, please migrate to a
valid format. 2020-04-17 21:42:42.240 INFO 10340 --- [
restartedMain] o.s.cloud.context.scope.GenericScope : BeanFactory
id=a11a283e-7de6-3470-b177-65c08eab7398 2020-04-17 21:42:43.859 INFO
10340 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer :
Tomcat initialized with port(s): 8765 (http) 2020-04-17 21:42:43.880
INFO 10340 --- [ restartedMain]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
logs of a service that is getting configurations:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:54:01.414 INFO 5180 --- [ restartedMain]
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server
at : http://localhost:8888 2020-04-17 21:54:04.184 INFO 5180 --- [
restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located
environment: name=users-service, profiles=[dev], label=null,
version=244114f5a11aa7d4a0acb5750ddad144f7de1be5, state=null
2020-04-17 21:54:04.186 INFO 5180 --- [ restartedMain]
b.c.PropertySourceBootstrapConfiguration : Located property source:
[BootstrapPropertySource {name='bootstrapProperties-configClient'},
BootstrapPropertySource
{name='bootstrapProperties-https://my-user#bitbucket.org/my-user/configs.git/users-service-dev.properties'},
BootstrapPropertySource
{name='bootstrapProperties-https://my-user#bitbucket.org/my-user/configs.git/users-service.properties'}]
2020-04-17 21:54:04.197 INFO 5180 --- [ restartedMain]
c.n.U.UsersServiceApplication : The following profiles are
active: dev
Is it logical to make gateway configuration dynamic?
Why don't I get the configuration from the configuration server?
Found the problem. I was missing:
implementation 'org.springframework.cloud:spring-cloud-starter-config'
in my build.gradle file dependencies

Run different profiles on Spring

I have an application where I need to run 3 profiles (united-states, france and vietnam) as shown in application.yml file shown below. These 3 profiles should come under registered service in my Eureka server that is running on port 9000.
I have run java -jar -Dspring.profiles.active=united-states xxx.jar to run my Spring application, but my Spring application defaults to port 8761 and my service is not registered in Eureka server.
---
# This default profile is used when running a single instance completely standalone:
spring:
profiles: default
server:
port: 9000
eureka:
instance:
hostname: my-eureka-server.com
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# united-states, france, and vietnam illustrate running 3 intercommunicating instances.
# This example has them running side-by-side on localhost
# -- which is unrealistic in production
# -- but does illustrate how multiple instances collaborate.
#
# Run by opening 3 separate command prompts:
# java -jar -Dspring.profiles.active=united-states SpringCloudServiceRegistrationEurekaServer.jar
# java -jar -Dspring.profiles.active=france SpringCloudServiceRegistrationEurekaServer.jar
# java -jar -Dspring.profiles.active=vietnam SpringCloudServiceRegistrationEurekaServer.jar
---
spring:
profiles: united-states
application:
name: eureka-server-clustered # ==> This is Service-Id
server:
port: 9001
eureka:
instance:
hostname: my-eureka-server-us.com
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://my-eureka-server-fr.com:9002/eureka/,http://my-eureka-server-vn.com:9003/eureka/
---
spring:
profiles: france
application:
name: eureka-server-clustered # ==> This is Service-Id
server:
port: 9002
eureka:
instance:
hostname: my-eureka-server-fr.com
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://my-eureka-server-us.com:9001/eureka/,http://my-eureka-server-vn.com:9003/eureka/
---
spring:
profiles: vietnam
application:
name: eureka-server-clustered # ==> This is Service-Id
server:
port: 9003
eureka:
instance:
hostname: my-eureka-server-vn.com
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://my-eureka-server-us.com:9001/eureka/,http://my-eureka-server-fr.com:9002/eureka/
Log:
2019-04-16 06:41:10.681 INFO 31061 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$75804a9c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.4.RELEASE)
2019-04-16 06:41:11.142 INFO 31061 --- [ main] rviceRegistrationEurekaServerApplication : The following profiles are active: united-states
2019-04-16 06:41:12.264 INFO 31061 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-04-16 06:41:12.284 INFO 31061 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 11ms. Found 0 repository interfaces.
2019-04-16 06:41:12.477 WARN 31061 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2019-04-16 06:41:12.825 INFO 31061 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=aedccd61-e8da-3db8-953a-28c197e2743c
2019-04-16 06:41:13.026 INFO 31061 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$5966479f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-16 06:41:13.076 INFO 31061 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$75804a9c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-16 06:41:13.530 INFO 31061 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8761 (http)
2019-04-16 06:41:13.573 INFO 31061 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-16 06:41:13.574 INFO 31061 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-16 06:41:13.690 INFO 31061 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-16 06:41:13.690 INFO 31061 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2525 ms
2019-04-16 06:41:13.887 WARN 31061 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-04-16 06:41:14.683 INFO 31061 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-04-16 06:41:15.126 INFO 31061 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-04-16 06:41:15.230 INFO 31061 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-04-16 06:41:15.316 INFO 31061 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.9.Final}
2019-04-16 06:41:15.320 INFO 31061 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-04-16 06:41:15.484 INFO 31061 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-04-16 06:41:15.769 INFO 31061 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2019-04-16 06:41:16.039 INFO 31061 --- [ main] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl#6c841199'
2019-04-16 06:41:16.043 INFO 31061 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-04-16 06:41:16.068 WARN 31061 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-04-16 06:41:16.362 INFO 31061 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-16 06:41:16.436 WARN 31061 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : 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
2019-04-16 06:41:17.084 INFO 31061 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-04-16 06:41:17.226 INFO 31061 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-04-16 06:41:17.290 INFO 31061 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application EUREKA-SERVER with eureka with status UP
2019-04-16 06:41:17.353 INFO 31061 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8761 (http) with context path ''
2019-04-16 06:41:17.354 INFO 31061 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8761
2019-04-16 06:41:17.360 INFO 31061 --- [ main] rviceRegistrationEurekaServerApplication : Started SpringCloudServiceRegistrationEurekaServerApplication in 7.941 seconds (JVM running for 8.624)
Note: I am using Intellij on Ubuntu and had configured my /etc/hosts file to include these hosts:
127.0.0.1 my-eureka-server.com
127.0.0.1 my-eureka-server-us.com
127.0.0.1 my-eureka-server-fr.com
127.0.0.1 my-eureka-server-vn.com
Your app is running as Eureka Server. If that's not what you expect, disable #EnableEurekaServer annotation if you have it on your #SpringBootApplication annotated class

Resources