Flyway migration failed - java

In classpath:/db.migration have migrations V1__Strory_create.sql and V2__Task_create.sql but flyway dosen't see that and fall with msg
2022-05-02 17:28:07.993 INFO 45296 --- [ restartedMain]
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server
at : http://localhost:8888/story 2022-05-02 17:28:08.213 INFO 45296
--- [ restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=story, profiles=[story], label=default,
version=null, state=null 2022-05-02 17:28:08.215 INFO 45296 --- [
restartedMain] b.c.PropertySourceBootstrapConfiguration : Located
property source: [BootstrapPropertySource
{name='bootstrapProperties-configClient'}, BootstrapPropertySource
{name='bootstrapProperties-classpath:/config/story.yml'}] 2022-05-02
17:28:08:331 INFO com.openhelp.story.StoryApplication - The following
1 profile is active: "default" 2022-05-02 17:28:11:368 DEBUG
com.zaxxer.hikari.HikariConfig - Driver class org.postgresql.Driver
found in Thread context class loader
org.springframework.boot.devtools.restart.classloader.RestartClassLoader#707d8885
2022-05-02 17:28:11:426 ERROR o.s.b.d.LoggingFailureAnalysisReporter -
*************************** APPLICATION FAILED TO START
Description:
Flyway failed to initialize: none of the following migration scripts
locations could be found:
classpath:db/migration
Action:
Review the locations above or check your Flyway configuration
Process finished with exit code 0
Configuration fetch from config service with bootstrap.yml
spring:
application:
name: story
profiles:
active: default
cloud:
config:
uri: ${vcap.services.configserver.credentials.uri:http://localhost:8888/story}
And fetched config
server:
port: 0
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}
client:
service-url:
defaultZone: http://localhost:8761/eureka
spring:
jpa:
generate-ddl: 'false'
properties:
hibernate:
jdbc:
time_zone: UTC
generate_statistics: 'false'
format_sql: 'true'
use_sql_comments: 'false'
show_sql: 'true'
hibernate:
ddl-auto: validate
open-in-view: 'false'
flyway:
baseline-on-migrate: 'true'
datasource:
driver-class-name: org.postgresql.Driver
password: '1'
username: postgres
url: jdbc:postgresql://127.0.0.1:5432/openhelp_story
autoconfigure:
exclude: org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
logging:
level:
org:
apache:
tomcat:
jdbc:
pool: debug
nodeValue: ERROR
springframework:
security: info
nodeValue: DEBUG
hibernate:
nodeValue: ERROR
jdbc: ERROR
stat: DEBUG
SQL: WARN
cache: ERROR
root: ERROR
com:
openhelp: debug
zaxxer:
hikari: debug
pattern:
console: '%d{yyyy-MM-dd HH:mm:ss:SSS} %-5level %logger{36} - %msg%n'
management:
endpoints:
jmx:
exposure:
include: health
openhelp:
logging:
path: logs
archive-path: logs/logs-archive
As we can see from log above the configuration fetched successully. Perhaps config is wrong?

Problem was in classpath:/db.migration instead of classpath:/db/migration. Accidentally I'm create one folder.

Related

Spring Cloud - Cannot Register Service with eureka server locally

I'm trying to configure the Eureka port with Spring Cloud with a eureka server, and config server (which is also a eureka client). Eureka service is successfully deployed and got a ip address. My Goal is to get the instance under eureka server.
I'm getting below error
2022-05-24 12:26:10.914 ERROR 21280 --- [freshExecutor-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}
2022-05-24 12:03:09.673 WARN 21280 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
This is my application.yml file from the test-service
spring:
datasource:
url: jdbc:oracle:thin:#//[ip address]/[address]
username: *******
password: *******
driver-class-name: oracle.jdbc.OracleDriver
profiles:
active:#activatedProperties#
jpa:
database-platform: org.hibernate.dialect.Oracle12cDialect
hibernate:
use-new-id-generator-mappings: false
ddl-auto: update
application:
name: test-service
eureka:
instance:
preferIpAddress: 'true'
client:
fetchRegistry: 'true'
registerWithEureka: 'true'
enabled: 'true'
service-url:
defaultZone: http://[username]:[password]#localhost:8761/eureka
server:
port: 8080
Debug: true
This is my eureka-serviece application.property file
server.port=8761
eureka.server.enable-self-preservation = false
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
spring.security.user.name=******
spring.security.user.password=*******
eureka.instance.preferIpAddress=true

How to activate another config file in application.yml in Spring Boot 2.6 new syntax?

I add new syntax in application.yml but failed.
Config file structure:
- resources
- application.yml
- application-dev.yml
- application-test.yml
In application.yml:
spring:
config:
activate:
on-profile: dev
In application-dev.yml:
server:
port: 9010
spring:
application:
name: account-service
datasource:
url: jdbc:mysql:///account_db
username: root
password: root
Runtime:
2022-04-20 14:16:02.354 INFO 13796 --- [ main] c.lingyuango.seckill.SeckillServiceMain : No active profile set, falling back to 1 default profile: "default"

HikariPool-1 - Exception during pool initialization(can not connect to database from springboot)

everyone. Forgive me for my poor English and strange grammar. I'm just beginning to learn Java
I got an error when try to query database,the application can be booted successfully.
enter image description here
when I query the database through the API,the error occurred.
2021-02-03 13:15:46.693 INFO 3761 --- [nio-8088-exec-3] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-02-03 13:15:46.693 INFO 3761 --- [nio-8088-exec-3] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-02-03 13:15:46.694 INFO 3761 --- [nio-8088-exec-3] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#c939991]
2021-02-03 13:15:46.759 INFO 3761 --- [nio-8088-exec-3] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2021-02-03 13:15:51.891 ERROR 3761 --- [nio-8088-exec-3] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
then i try to connect the local database via Navicat,succeed
enter image description here
here is my application.yml
server:
port: 8088
tomcat:
uri-encoding: UTF-8
max-http-header-size: 80KB
spring:
profiles:
active: dev
datasource: # 数据源的相关配置
type: com.zaxxer.hikari.HikariDataSource # 数据源类型:HikariCP
driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动
url: jdbc:mysql://localhost:3306/demo-shop?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=CST
username: root
password: 12345678
hikari:
connection-timeout: 30000 # 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 默认:30秒
minimum-idle: 10 # 最小连接数
maximum-pool-size: 10 # 最大连接数
auto-commit: true # 自动提交
idle-timeout: 600000 # 连接超时的最大时长(毫秒),超时则被释放(retired),默认:10分钟
pool-name: DateSourceHikariCP # 连接池名字
max-lifetime: 1800000 # 连接的生命时长(毫秒),超时而且没被使用则被释放(retired),默认:30分钟 1800000ms
connection-test-query: SELECT 1
servlet:
multipart:
max-file-size: 512000 # 文件上传大小限制为500kb
max-request-size: 512000 # 请求大小限制为500kb
mybatis:
mapper-locations: classpath:mapper/*.xml # mapper映射文件
type-aliases-package: com.mooc.pojo # 所有POJO类所在包路径
# mapper-locations: classpath:mapper/*.xml # mapper映射文件
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper:
mappers: com.mooc.my.mapper.MyMapper
not-empty: false # 在进行数据库操作的的时候,判断表达式 username != null, 是否追加 username != ''
identity: MYSQL
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.2.4</version>
</dependency>
What happened?:(
problem solved
before
url: jdbc:mysql://localhost:3306/demo-shop?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=CST
username: root
password: 12345678
after
url: jdbc:mysql://localhost:3306/demo-shop?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=CST
username: root
password: 12345678

data.sql is not invoked on startup

I have following application.yml:
spring:
profiles: test
jpa:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
generate-ddl: true
ddl-auto: true
datasource:
url: jdbc:h2:mem:test_db;MODE=MSSQLServer
username: sa
password:
data: data.sql
continue-on-error: true
flyway:
enabled: false
and following project structure:
But data.sql is not invoked on startup

Remove other profiles from spring configuration file

I have application.yaml configuration file with few profiles:
server:
address: 0.0.0.0
port: 9090
db:
url: 'jdbc:postgresql://localhost:5432/the_db'
driver: 'org.postgresql.Driver'
username: 'postgres'
password: ''
---
spring:
profiles: devArtem
db:
url: 'jdbc:postgresql://localhost:5432/my_db'
---
spring:
profiles: prod_1
db:
password: 'first_pass'
---
spring:
profiles: prod_2
db:
password: 'second_pass'
And I want to remove other profiles before build jar file. I don't want to give access for prod_1's password to prod_2 platform for example.
For prod_1 it must be something like this:
server:
address: 0.0.0.0
port: 9090
db:
url: 'jdbc:postgresql://localhost:5432/the_db'
driver: 'org.postgresql.Driver'
username: 'postgres'
password: 'first_pass'
or this:
server:
address: 0.0.0.0
port: 9090
db:
url: 'jdbc:postgresql://localhost:5432/the_db'
driver: 'org.postgresql.Driver'
username: 'postgres'
password: ''
---
spring:
profiles: prod_1
db:
password: 'first_pass'
You can use multiple application-{profile}.yml and give each team the right file.
for example :
application-devArtem.yml ---> to team devArtem
application-prod_1.yml ---> to team prod_1
application-prod_2.yml ---> to team prod_2

Categories

Resources