How to run flyway migration for reactive r2dbc driver on sprintboot stratup - spring-boot

I am working on springboot webflux project with non-blocking database driver r2dbc,
But when Springboot application start Flyway does not run migrations.
Below are my spring-boot 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.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>r2dbmigration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>r2dbmigration</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-test-autoconfigure-r2dbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-bom-r2dbc</artifactId>
<version>0.1.0.M3</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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
</project>
My migration file is : V1.1__create_file_import_table.sql
with content of
DROP TABLE IF EXISTS file_import;
CREATE TABLE file_import
(
id BIGINT GENERATED ALWAYS AS IDENTITY,
file_key CHARACTER VARYING(255) NOT NULL,
created_at TIMESTAMP without time zone NOT NULL,
created_by BIGINT NOT NULL,
PRIMARY KEY (id)
);
application.properties
spring.r2dbc.url= r2dbc:postgresql://localhost:5432/import
spring.r2dbc.username=postgres
spring.r2dbc.password=password
My application starts smoothly but there is no migration run.
Can someone please help me ?
Github URL
Thanks

The following Java implementation is based on #Sim's Kotlin example.
Example 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.3.0.RC1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>flyway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>flyway</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-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>dev.miku</groupId>
<artifactId>r2dbc-mysql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>
Example application.yml
---
spring:
r2dbc:
url: r2dbc:pool:mysql://localhost:3306/defaultdb
username: <user>
password: <pass>
flyway:
url: jdbc:mysql://localhost:3306/defaultdb
user: ${spring.r2dbc.username}
password: ${spring.r2dbc.password}
baseline-on-migrate: true
Add the following Spring Boot configuration - FlywayConfig.java
package com.example.flyway;
import org.flywaydb.core.Flyway;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
// https://stackoverflow.com/a/61412233
#Configuration
public class FlywayConfig {
private final Environment env;
public FlywayConfig(final Environment env) {
this.env = env;
}
#Bean(initMethod = "migrate")
public Flyway flyway() {
return new Flyway(Flyway.configure()
.baselineOnMigrate(true)
.dataSource(
env.getRequiredProperty("spring.flyway.url"),
env.getRequiredProperty("spring.flyway.user"),
env.getRequiredProperty("spring.flyway.password"))
);
}
}
First execution:
: Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
: Finished Spring Data repository scanning in 7ms. Found 0 R2DBC repository interfaces.
: Flyway Community Edition 6.4.1 by Redgate
: Database: jdbc:mysql://localhost:3306/defaultdb (MySQL 5.5)
: Successfully validated 1 migration (execution time 00:00.006s)
: Creating Schema History table `defaultdb`.`flyway_schema_history` ...
: DB: Name 'flyway_schema_history_pk' ignored for PRIMARY key. (SQL State: 42000 - Error Code: 1280)
: Current version of schema `defaultdb`: << Empty Schema >>
: Migrating schema `defaultdb` to version 1.0.001 - Initialise database tables
: Successfully applied 1 migration to schema `default` (execution time 00:00.036s)
: Netty started on port(s): 8080
:Started Application in 1.829 seconds (JVM running for 2.343)
Second execution:
: No active profile set, falling back to default profiles: default
: Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
: Finished Spring Data repository scanning in 11ms. Found 0 R2DBC repository interfaces.
: Flyway Community Edition 6.4.1 by Redgate
: Database: jdbc:mysql://localhost:3306/defaultdb (MySQL 5.5)
: Successfully validated 1 migration (execution time 00:00.009s)
: Current version of schema `defaultdb`: 1.0.001
: Schema `defaultdb` is up to date. No migration necessary.
: Netty started on port(s): 8080
: Started Application in 1.273 seconds (JVM running for 1.695)

A bit late answer, but you can also set up a Spring bean manually to handle the migration.
Add flyway config to application.yml (or .properties):
spring:
flyway:
url: jdbc:postgresql://localhost:5432/<db-name>
user: <user>
password: <password>
This code is Kotlin, but it can easily be translated to Java:
import org.flywaydb.core.Flyway
import org.springframework.boot.autoconfigure.flyway.FlywayProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
#Configuration
class FlywayConfig(private val flywayProperties: FlywayProperties) {
#Bean(initMethod = "migrate")
fun flyway(): Flyway? {
return Flyway(Flyway.configure()
.baselineOnMigrate(true)
.dataSource(flywayProperties.url, flywayProperties.user, flywayProperties.password)
)
}
}

Solved this by using the combination of Flyway + JDBC, and R2DBC for the rest of DB interactions.
application.properties
my.database.url=postgresql://localhost:5432}/my_database
spring.r2dbc.url=r2dbc:${my.database.url}
spring.r2dbc.username=user
spring.r2dbc.password=pass
spring.flyway.locations=classpath:db/migration
spring.flyway.enabled=true
spring.flyway.validate-on-migrate=true
spring.flyway.user=${spring.r2dbc.username}
spring.flyway.password=${spring.r2dbc.password}
spring.flyway.url=jdbc:${my.database.url}
build.gradle
dependencies {
...
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
runtimeOnly 'org.flywaydb:flyway-core:7.9.1'
runtimeOnly 'org.postgresql:postgresql:42.2.20'
runtimeOnly 'io.r2dbc:r2dbc-postgresql'
runtimeOnly 'org.springframework.boot:spring-boot-starter-jdbc'
...
}
Location of flyway migration SQL scripts:
src/main/resources/db/migration/V1__create_my_table.sql

It seems like there is no "official" solution for this problem yet, but there is a temporary solution to solve that: "R2DBC migration tool".
#Nikita Konev provide us a good temporary solution for this problem. I have been using that and works well.
Please check:
R2DBC support - Flyway: https://github.com/flyway/flyway/issues/2502
R2DBC migration tool: https://github.com/nkonev/r2dbc-migrate
Example project (you can play around): https://github.com/nkonev/r2dbc-migrate-example
Thanks to Nikita Konev

This might be delayed response, but personally, I prefer to just add the spring starter.
This worked for me:
// build.gradle.kts
implementation("org.flywaydb:flyway-core:7.9.1")
runtimeOnly("org.springframework.boot:spring-boot-starter-jdbc")
runtimeOnly("org.postgresql:postgresql:42.2.20")
Then your application.yml file can look like:
# application.yml
spring:
r2dbc:
url: r2dbc:postgresql://user:pass#host/db
flyway:
enabled: true
validate-on-migrate: true
user: user
password: pass
url: jdbc:postgresql://host:5432/db
schemas: ["schema"]

As mentioned in the comments: R2DBC and Flyway are not compatible yet.
A workaround is to execute Flyway migration using the Maven Flyway plugin, note that you need to provide a JDBC-URL.
In your case, you can trigger the migration via
mvn flyway:migrate -Dflyway.url=jdbc:postgresql://localhost:5432/import -Dflyway.user=postgres -Dflyway.password=password
or via
mvn flyway:migrate
if you add the plugin+configuration in your pom.xml
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.1.3</version>
<configuration>
<url>jdbc:postgresql://localhost:5432/import</url>
<user>postgres</user>
<password>password</password>
</configuration>
</plugin>
execute the migration via

Related

Spring Boot Application displays no error, but tomcat not initialized and application.properties is unused

I created a new project using Spring Initializr, and opened it with Intellij IDEA version 2020.3.2 ide. After maven installed all dependencies in the pom.xml file, I ran the main method in the DemoApplication class. I didn't add anything new or different than the default project created by the Spring Initializr.
Two Problems occured:
1- Console outputted only these 3 logs, and Tomcat wasn't initialized
2021-02-03 23:48:45.073 INFO 15872 --- [ main] com.example.DemoApplication: Starting DemoApplication using Java 1.8.0_281 on DESKTOP-M with PID 15872 (D:\demo\target\classes started by M in D:\demo)
2021-02-03 23:48:45.078 INFO 15872 --- [ main] com.example.DemoApplication : No active profile set,falling back to default profiles: default
2021-02-03 23:48:46.355 INFO 15872 --- [ main] com.example.DemoApplication: Started DemoApplication in 2.062 seconds (JVM running for 2.87)
Process finished with exit code 0
2- Anything I write in the application.properties file turns grey (unused)
I watched a lot of tutorials, and did exactly as they do. Their console output always has more than 3 statements and is even colored, which mine isn't
My 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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</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>
DemoApplication.java
package com.example;
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);
}
}
Would appreciate it if you would help me figure out how to correctly run the project and have the server up and running.
Should I add anymore run Options?
External Libraries:
This issue is reproducible with a simple war initializer, when you run DemoApplication with a "standalone java" (IDE run) configuration.
The solution/correct usage is: To run (the project) in a "maven" spring-boot:run (IDE run) configuration.
Like:
It looks like you are using IntelliJ IDEA Community Edition which has no support for Spring Boot.
That is why the properties are not highlighted and the output is not colored.
IntelliJ IDEA Ultimate will use Spring Boot Run/Debug configuration type automatically:
As a workaround you can run your code via Maven spring-boot:run.
I saw the same behavior when I setup a project with pox.xml you provided.
The "Include dependencies with "Provided" fixed it for me. However I had to reload the Maven dependencies like this a few times: pom.xml (right click) -> Maven -> Reload Project.
I would still suggest that you remove <scope>provided</scope> in spring-boot-starter-tomcat.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!-- Comment this out -->
<!-- <scope>provided</scope> -->
</dependency>
Here is a good answer - Java Spring Boot - spring-boot-starter-tomcat dependency doesn't work with scope provided when running locally
If you still need this project to run in an external Tomcat container and thus want to mark the spring-boot-spring-boot-starter dependency as "provided", you can specify a separate profile for that configuration - https://stackoverflow.com/a/42302247

Trying to access .properties file using spring server and cloud. Works on local repo but not in git remote repo

I am working on microservices using springboot. While configuring the server, everything is going smoothly. I am working on springboot 2.4 with cloud version 2020.0.0.
enabled #EnableConfigServer on the main application class
added bootstrap dependency
created new git repo and property file
added configuration to the pom file
But when I work with a local git repo, my server responds and I can access the application through URL (eg. localhost:8888/client/default).
However, when I provide my remote git URL, the server does not respond to anything. My URL is correct and I have provided the username and passwords too.
There are no errors and nothing. Only 404 error page created by springboot.
What is the issue here? can anyone help?
POM::
<?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.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.config</groupId>
<artifactId>server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>server</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2020.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</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>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>
Main Class::
#SpringBootApplication
#EnableConfigServer
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
application.properties::
spring.config.name= server
server.port= 8888
spring.cloud.config.server.git.uri=https://github.com/chiranjiviNeupane/MicroserviceRepo
spring.cloud.config.server.git.username= chiranjiviNeupane
spring.cloud.config.server.git.password= ********
spring.cloud.config.server.git.clone-on-start= true
management.endpoints.web.exposure.include= *
But when I replace spring.cloud.config.server.git.url with local repo works fine. However, implementing a remote git address does not work. It doesn't give any errors too.
I found your git repository has main branch not master which is default branch for cloud config server.
To resolve this, you need to run client with property -Dspring.cloud.config.label=main or create master branch from main branch.

In Creating a Spring Boot application with a flyway H2 embedded database I am having trouble getting the SQL file to run

I have my SQL file titled V2__create_shipwrech.sql. The above file is located in the migration folder of the following path das-boot/src/main/resources/db/migration.
Here's the SQL content:
CREATE TABLE SHIPWRECK(
ID INT AUTO_INCREMENT,
NAME VARCHAR(255),
DESCRIPTION VARCHAR(2000),
CONDITION VARCHAR(255),
DEPTH INT,
LATITUDE DOUBLE,
LONGITUDE DOUBLE,
YEAR_DISCOVERED INT
);
Here's my application.properties file contents:
logging.level.org.springframework.web=DEBUG
server.port=8080
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:file:~/dasboot
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.max-active=10
spring.datasource.max-idle=8
spring.datasource.max-wait=10000
spring.datasource.min-evictable-idle-time-millis=1000
spring.datasource.min-idle=8
spring.datasource.time-between-eviction-runs-millis=1
flyway.baseline-on-migrate=true
spring.jpa.hibernate.ddl-auto=false;
Here's my pom file contents:
<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>com.boot</groupId>
<artifactId>das-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<name>das-boot</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
This is my first time working with Spring Boot, Flyway, and the h2 embedded database, so please for give me if I sound like a newbie at this, I am.
Here's my console output lines I think stand out to me:
- Database: jdbc:h2:file:~/dasboot (H2 1.4)
- Validated 1 migration (execution time 00:00.039s)
- Current version of schema "PUBLIC": 2
- Schema "PUBLIC" is up to date. No migration necessary.
- Building JPA container EntityManagerFactory for persistence unit 'default'
- Processing PersistenceUnitInfo [
- name: default
- ...]
- Hibernate Core {4.3.11.Final}
- hibernate.properties not found
- HHH000021: Bytecode provider name : javassist
- Hibernate Commons Annotations {4.0.5.Final}
- Unrecognized value for "hibernate.hbm2ddl.auto": false;
- Looking for #ControllerAdvice:
Then there were a ton of debug statements saying bean that were rejected after that, which I don't have enough room to paste.
This was all using java version 1.8
Any help would be greatly appreciated and what I learn from you will be used to teach others as I progress.
Thanks in advance,
Joe
Modify the property spring.jpa.hibernate.ddl-auto=false to
spring.jpa.hibernate.ddl-auto=none

spring boot + jboss = page 403

I was trying to connect spring boot with jboss for a week... I read many topics on this forum and many of them are too old. I get error 404 every time when i want run server. Can you please help me to config my app with jboss properly?
UPDATE:
Thank you for help with error 404. I changed package to "war". But now when I run wildfly server Im getting error 403 (forbidden). I was looking how to fix it and still stay in the same place. It is so hard to get wildfly work with spring boot...
I updated files:
https://github.com/kuzyn007/LibraryCRUD
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.seweryn</groupId>
<artifactId>LibraryCRUD</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!-- Spring: boot starter parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<!-- Starter for building web, including RESTful, applications using Spring
MVC. Uses Tomcat as the default embedded container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Starter for using Spring Data JPA with Hibernate -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<!-- Starter for testing Spring Boot applications with libraries including
JUnit, Hamcrest and Mockito -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- The spring-boot-devtools module can be included in any project to
provide additional development-time features. -->
<!-- Applications that use spring-boot-devtools will automatically restart
whenever files on the classpath change. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- JSP Standard Tag Library -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.servlet.jsp</groupId>
<artifactId>jboss-jsp-api_2.2_spec</artifactId>
<version>1.0.2.Final</version>
</dependency>
<!-- … -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- … -->
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<build>
<finalName>LibraryCRUD</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.properties
# MVC
spring.view.prefix=/WEB-INF/jsp/
spring.view.suffix=.jsp
# JNDI
spring.datasource.jndi-name=java:jboss/datasources/library
# JPA/HIBERNATE
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.naming.physical-strategy=pl.seweryn
spring.jpa.database=H2
spring.jpa.show-sql=true
Application.java
package pl.seweryn.init;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
//#Configuration
//#EnableAutoConfiguration
//#ComponentScan
#SpringBootApplication // same as #Configuration #EnableAutoConfiguration #ComponentScan - alternative
public class Application extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Follow this instructions: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
You basically have to package your app as a WAR and implement SpringBootServletInitializer.
I found many mistakes in my project and now its working. I will write here answer for my app.
Physical naming was wrong. It should be: spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl. Or I could delete this line and it will be provided default from spring boot
I have Application.class in pl.seweryn.init package. I added #ComponentScan(pl.seweryn)
BookDaoImpl was not a spring component. Added line #Component

Unable to import Spring RepositoryRestResource

I am trying to implement a REST based MongoDB service through Spring, but I have run into some trouble. I cannot import a certain library.
I have this in my class:
package main;
import java.util.List;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
#RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends MongoRepository<Person, String> {
List<Person> findByLastName(#Param("name") String name);
}
But the import org.springframework.data.rest.core.annotation.RepositoryRestResource;
is not working for some reason and is giving me the error: The import org.springframework.data.rest cannot be resolved
This is my maven pom.xml:
<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>UserRegistrationServices</groupId>
<artifactId>UserRegistrationServices</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Get the dependencies of a web application -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Spring Boot Maven Support -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Also, I am directly following this guide: http://spring.io/guides/gs/accessing-mongodb-data-rest/
How can this be resolved? Thanks
Edit your pom.xml.... and add these lines inside <dependencies></dependencies>...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
I had a same problem on 1.3.6.RELEASE.
It said,
org.springframework.data.rest.core.annotation.RepositoryRestResource cannot be resolved to a type
So I set the version of spring-boot as 1.2.8.RELEAS, now I solve the problem.
My current spring-boot's pom.xml is below.
....
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.8.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
....
I had the same problem with this error message. In my case was the cause a refresh problem in the IDE (Intellij).
Deleting the line with the annotation (#RepositoryRestResource) and reinsert it helped a lot.
I also had tried to follow the same from https://spring.io/guides/gs/accessing-mongodb-data-rest/
For me, this issue got resolved after I added the version from https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-rest/2.3.0.RELEASE
to be more precise and clear, I added this in the pom.xml file to solve this issue. Maybe if you add the version it will start working!
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-rest -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<version>2.3.0.RELEASE</version>
</dependency>

Resources