My microservice for running migrations with Liquibase and MongoDB doesn't execute the migration when the server starts up, as claimed to do with Spring Boot.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
spring:
application:
name: photo-app-liquibase
datasource:
driver-class-name: liquibase.ext.mongodb.database.MongoClientDriver
url: mongodb://localhost:27017/photo-app
liquibase:
change-log: classpath:db/changelog/db.changelog-master.xml
The migration and master file are located in src/main/resources/db/changelog folder
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<!-- Tried without "db/changelog" and appending "./" before already -->
<include file="db/changelog/20201029215628_create-users-table.xml"/>
</databaseChangeLog>
But when starting up the server, no sign of the migration being run and also nothing changes in the database.
2020-10-30 08:32:04.928 INFO 12065 --- [ main] c.g.p.PhotoAppLiquibaseApplication : Starting PhotoAppLiquibaseApplication on gabriel with PID 12065 (/home/gabriel/Workspace/spring/spring-microservices-ii/photo-app-liquibase/target/classes started by gabriel in /home/gabriel/Workspace/spring/spring-microservices-ii/photo-app-discovery-service)
2020-10-30 08:32:04.933 INFO 12065 --- [ main] c.g.p.PhotoAppLiquibaseApplication : No active profile set, falling back to default profiles: default
2020-10-30 08:32:05.559 INFO 12065 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2020-10-30 08:32:05.582 INFO 12065 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 MongoDB repository interfaces.
2020-10-30 08:32:05.864 INFO 12065 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2020-10-30 08:32:05.920 INFO 12065 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:22}] to localhost:27017
2020-10-30 08:32:05.928 INFO 12065 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=4278944}
2020-10-30 08:32:06.134 INFO 12065 --- [ main] c.g.p.PhotoAppLiquibaseApplication : Started PhotoAppLiquibaseApplication in 1.729 seconds (JVM running for 2.57)
Process finished with exit code 0
Liquibase doesn't support MongoDB, but they provide an extension to support MongoDB:
=> How to use Liquibase-MongoDb-Spring-boot
Related
My localhost does not load the page:
http://localhost:8080/
This site can’t be reached
localhost refused to connect.
I have a brand new project and when I run the project I don't get any errors or see any errors but when I try to view using the localhost I see the above error
Here is the detail on my project.
Java version on my machine:
C:\WINDOWS\system32>java -version java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
I have no idea what I'm doing wrong here, and again I have nothing except this class which I run:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
My POM file:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.4.2
com.example
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</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>
Application log:
2021-01-16 19:24:07.268 INFO 23308 --- [ main]
com.example.demo.DemoApplication : Starting DemoApplication
using Java 13.0.2 on XPS8910 with PID 23308
(C:\Users\nick\eclipse-workspace\demo\target\classes started by
XPS89100 in C:\Users\nick\eclipse-workspace\demo) 2021-01-16
19:24:07.270 INFO 23308 --- [ main]
com.example.demo.DemoApplication : No active profile set,
falling back to default profiles: default 2021-01-16 19:24:07.740
INFO 23308 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
JPA repositories in DEFAULT mode. 2021-01-16 19:24:07.752 INFO 23308
--- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 4 ms. Found 0 JPA
repository interfaces. 2021-01-16 19:24:08.143 INFO 23308 --- [
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized
with port(s): 8080 (http) 2021-01-16 19:24:08.151 INFO 23308 --- [
main] o.apache.catalina.core.StandardService : Starting service
[Tomcat] 2021-01-16 19:24:08.151 INFO 23308 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine:
[Apache Tomcat/9.0.41] 2021-01-16 19:24:08.274 INFO 23308 --- [
main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring
embedded WebApplicationContext 2021-01-16 19:24:08.274 INFO 23308 ---
[ main] w.s.c.ServletWebServerApplicationContext : Root
WebApplicationContext: initialization completed in 961 ms 2021-01-16
19:24:08.429 INFO 23308 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [name: default] 2021-01-16 19:24:08.473 INFO
23308 --- [ main] org.hibernate.Version :
HHH000412: Hibernate ORM core version 5.4.27.Final 2021-01-16
19:24:08.586 INFO 23308 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.1.2.Final} 2021-01-16 19:24:08.670 INFO 23308
--- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
It looks like spring application didn't start completely and freezes on starting Hikari Pool (last line in your log).
Hikari pool is a database connection pool. This probably means that the DB connection settings in your application.properties are incorrect and connection can't be established.
Can you verify that database is running and responding on the datasource URL you configured?
When I run my application using
mvn spring-boot:run
my application, which does not use MongoDB, bootstraps some unknown MongoDB Repository. Is there any way to remove this or disable it?
2020-06-26 09:45:56.632 INFO 15712 --- [ main] com.cisco.hr.wfpo.WfpoApplication : No active profile set, falling back to default profiles: default
2020-06-26 09:46:01.083 INFO 15712 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-06-26 09:46:01.620 INFO 15712 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 504ms. Found 23 JPA repository interfaces.
2020-06-26 09:46:01.750 INFO 15712 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
2020-06-26 09:46:01.873 INFO 15712 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 117ms. Found 0 Reactive MongoDB repository interfaces.
2020-06-26 09:46:01.893 INFO 15712 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
You have Spring Data MongoDB dependencies that are detected by Spring Data.
if you have below two starters, simply remove them
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
I want to start the Spring Boot Admin server on a different port than 8080.
So I configured the server.port property in the bootstrap.yml file with 9000, but still the server listens on port 8080 according to the log file.
Here's my bootstrap.yml:
server:
port: 9000
spring:
application:
name: admin-server
cloud:
config:
uri: http://localhost:8888
And this is the final part of the console log:
2018-11-29 15:52:11.242 INFO 25999 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-11-29 15:52:11.271 INFO 25999 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-11-29 15:52:11.274 INFO 25999 --- [ main] n.d.d.c.a.AdminServerApplication : Started AdminServerApplication in 2.826 seconds (JVM running for 3.355)
2018-11-29 15:52:11.818 INFO 25999 --- [on(4)-127.0.0.1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-11-29 15:52:11.819 INFO 25999 --- [on(4)-127.0.0.1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-11-29 15:52:11.830 INFO 25999 --- [on(4)-127.0.0.1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 11 ms
In the application.properties file put this
server.port = 9000
A flashlight in my brain told me I might have forgotten to add the spring-cloud-config-client dependency, after checking, and then adding the appropriate dependency to the pom.xml, it worked like a charm:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
Thanks to all for providing feedback.
Many different configuration sources have precedence over application.properties (or YAML) as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
You might need to verify if one of those sources are not interfering with the value of serve.port.
I have used Embedded derby earlier in my spring boot projects. But now when i created the project through Spring Initializr with the derby dependency. I get the below error :
Schema 'SA' does not exist
followed by org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
When i tried running the earlier project that i had created, the Derby is working just fine.
PFB the console for the earlier project :
2018-03-18 15:34:44.346 INFO 16560 --- [ restartedMain]
org.hibernate.cfg.Environment : HHH000021: Bytecode
provider name : javassist 2018-03-18 15:34:44.391 INFO 16560 --- [
restartedMain] o.hibernate.annotations.common.Version : HCANN000001:
Hibernate Commons Annotations {5.0.1.Final} 2018-03-18 15:34:44.490
**INFO 16560 --- [ restartedMain] org.hibernate.dialect.Dialect
: HHH000400: Using dialect: org.hibernate.dialect.DerbyDialect
2018-03-18 15:34:44.497 WARN 16560 --- [ restartedMain]
org.hibernate.dialect.DerbyDialect : HHH000430: The DerbyDialect
dialect has been deprecated; use one of the version-specific dialects
** instead 2018-03-18 15:34:45.094 INFO 16560 --- [ restartedMain]
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl
schema export 2018-03-18 15:34:45.099 ERROR 16560 --- [
restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389:
Unsuccessful: drop table book 2018-03-18 15:34:45.099 ERROR 16560 ---
[ restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport : Schema
'SA' does not exist 2018-03-18 15:34:45.129 WARN 16560 --- [
restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning
Code: 10000, SQLState: 01J01 2018-03-18 15:34:45.129 WARN 16560 --- [
restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper : Database
'memory:testdb' not created, connection made to existing database
instead. 2018-03-18 15:34:45.129 INFO 16560 --- [ restartedMain]
org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export
complete 2018-03-18 15:34:45.152 INFO 16560 --- [ restartedMain]
j.LocalContainerEntityManagerFactoryBean : Initialized JPA
EntityManagerFactory for persistence unit 'default'
The Console Log for my current spring boot with embedded derby :
2018-03-18 15:42:23.234 INFO 11312 --- [ main]
com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-03-18 15:42:23.237 WARN 11312 --- [ main]
**com.zaxxer.hikari.util.DriverDataSource : Registered driver with
driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found,
trying direct instantiation. 2018-03-18 15:42:23.844 INFO 11312 --- [
** main] com.zaxxer.hikari.pool.PoolBase : HikariPool-1 - Driver
does not support get/set network timeout for connections. (Feature not
implemented: No details.) 2018-03-18 15:42:23.847 INFO 11312 --- [
main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start
completed. 2018-03-18 15:42:23.937 INFO 11312 --- [ main]
j.LocalContainerEntityManagerFactoryBean : Building JPA container
EntityManagerFactory for persistence unit 'default' 2018-03-18
15:42:23.969 INFO 11312 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [ name: default ...] 2018-03-18 15:42:24.136
INFO 11312 --- [ main] org.hibernate.Version
: HHH000412: Hibernate Core {5.2.14.Final} 2018-03-18 15:42:24.138
INFO 11312 --- [ main] org.hibernate.cfg.Environment
: HHH000206: hibernate.properties not found 2018-03-18 15:42:24.199
INFO 11312 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.0.1.Final} 2018-03-18 15:42:24.380 INFO 11312
--- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
2018-03-18 15:42:25.572 WARN 11312 --- [ main]
o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget
encountered exception accepting command : Error executing DDL via JDBC
Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error
executing DDL via JDBC Statement at
org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
~[hibernate-core-5.2.14.Final.jar:5.2.14.Final] at
org.hibernate.tool.schema.internal.SchemaDropperImpl.applySqlString(SchemaDropperImpl.java:375)
[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
The difference i can find between the two is that in the current log(abv log) it says that the
com.zaxxer.hikari.util.DriverDataSource : Registered driver with
driverClassName=org.apache.derby.jdbc.EmbeddedDriver was not found,
trying direct instantiation.
Let me know if we need to configure something apart from the below dependency for enabling this derby. Note- I dint do anything apart from maven dependency in the previous project.
Maven dependency :
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
Please configure you JPA Configuration as per your requirement. I've configured as below. You need to add below configuration in application.properties file.
# PROFILES
spring.profiles.active=dev
# JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.continue-on-error=false
spring.datasource.generate-unique-name=false
add
spring.jpa.hibernate.ddl-auto=update
to your application.properties
it is by default create-drop.
The default driver used by derby is org.apache.derby.jdbc.AutoloadedDriver, but springboot and other framework choice org.apache.derby.jdbc.EmbeddedDriver.
It causes the driver to be unable to find the driver when using the datasource for the first time.
About Schema 'SA' does not exist.
I think that you use the other tool connect the derby, such as ij. And the jdbc url they use is the same. It looks like the same database connected, but it's not actually.
This is the key to the problem.
Added this in appplication.properties and worked
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database=default
spring.jpa.show-sql=true
I've added below property in application.properties, it worked!
spring.jpa.hibernate.ddl-auto=update
The spring application won't run as web application and does not use the embedded tomcat server. I have provided my console and pom.xml logs. Please help me.
2017-03-17 01:38:09.426 INFO 18696 --- [ main] io.springbootstarter.SpringCourseApi : Starting SpringCourseApi on gandy with PID 18696 (C:\Spring\workspace\course-api\target\classes started by gandhar in C:\Spring\workspace\course-api)
2017-03-17 01:38:09.431 INFO 18696 --- [ main] io.springbootstarter.SpringCourseApi : No active profile set, falling back to default profiles: default
2017-03-17 01:38:09.539 INFO 18696 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#5ae50ce6: startup date [Fri Mar 17 01:38:09 MDT 2017]; root of context hierarchy
2017-03-17 01:38:11.361 INFO 18696 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-03-17 01:38:11.383 INFO 18696 --- [ main] io.springbootstarter.SpringCourseApi : Started SpringCourseApi in 2.662 seconds (JVM running for 3.22)
2017-03-17 01:38:11.384 INFO 18696 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#5ae50ce6: startup date [Fri Mar 17 01:38:09 MDT 2017]; root of context hierarchy
2017-03-17 01:38:11.385 INFO 18696 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
This is my console output when i try to run a web application. My pom.xml looks like this -
<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>
<groupId>org.springboot.courses</groupId>
<artifactId>course-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Course_API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>