jdbc:h2:file:./h2_db, tables don't exist.(springboot, jpa) - java

I just made H2database file. but when I log in h2console. my tables don't show up. am i missing something in application.yml?
spring:
profiles: dev
datasource:
url: jdbc:h2:file:./h2_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
driver-class-name: org.h2.Driver
username: root
password: 1
h2:
console:
enabled: true
settings:
web-allow-others: true
jackson:
serialization:
fail-on-empty-beans: false
deserialization:
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE: true
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: true
show_sql: true
default_batch_fetch_size: 100

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

Flyway migration failed

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.

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"

H2 - Oracle - liquibase - org.h2.jdbc.JdbcSQLException: Table "all_sequences" not found;

I try to add H2 for testing purpose into Spring Boot application-test.yml, my production Db is Oracle. I want to populate H2 schema by liquibase, but I receive following error:
Caused by: org.h2.jdbc.JdbcSQLException: Table "all_sequences" not
found; SQL statement:
My config is following:
spring:
profiles:
active: test
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=Oracle
username: sa
password:
platform: h2
driver-class-name: org.h2.Driver
jpa:
hibernate:
ddl-auto: none
generate-ddl: true
h2:
console:
enabled: true
path: /console
liquibase:
url: ${spring.datasource.url}
enabled: true
user: sa
password:
change-log: classpath:liquibase/test-master.xml
drop-first: true
How to adjust config aboive, I spent few hours, but can not figure out how to make it work.
Adding:
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
Solved problem.
Full config:
spring:
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=Oracle
username: sa
password:
platform: h2
driver-class-name: org.h2.Driver
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: none
generate-ddl: true
liquibase:
url: ${spring.datasource.url}
contexts: test
change-log: classpath:liquibase/test-master.xml
user: sa
password:
all_sequences is Oracle specific DB table. You should only migrate the user defined tables.

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

Categories

Resources