baseline-on-migrate with Flyway and Spring Boot - spring-boot

I have seen this posted before but I had already implemented the solutions offered and so I am asking again with more detail to my specific situation. I am trying to integrate Flyway in my SpringBoot app (using H2). I have added the following to the pom.xml:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
and to application.properties I have tried both:
flyway.baselineOnMigrate=true
and:
flyway.baseline-on-migrate=false
but I consistently get the error:
Found non-empty schema(s) "PUBLIC" without schema history table! Use baseline() or set baselineOnMigrate to true to initialize the schema history table.
I have tried a variety of other solutions I've seen posted, including adding Flyway as a plugin and not just dependency in the POM, but nothing seems to be working. Does anyone know what I'm missing? Thanks!

I know it is a bit old question, but in Spring boot 2.x you should use spring.flyway.baseline-on-migrate = true instead

Related

Is there compatibility between Uni<> and Reactor's Mono<>?

I'm trying to connect Hibernate Reactive and Spring WebFlux(Project Reactor most).
The problem is that Uni<>(Hibernate Reactive type) replaces Mono<> (Reactive type from Project Reactor), and from now, behaviour is not such obviously, as Project Reactor provides without other reactive types.
Is there are some tools for compatibility between Uni<> and Reactor's Mono<>/Flux<>?
Already Investigated GitHub repos, tried to connect reactive types via custom spring starters.
Yes, there is support to convert between the two type systems.
Add the following dependency...
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny-reactor</artifactId>
<version>1.7.0</version>
</dependency>
...and use the following code:
Mono<T> monoFromUni = uni.convert().with(UniReactorConverters.toMono());
You can find detailed documentation here: https://smallrye.io/smallrye-mutiny/1.7.0/guides/converters/

springdoc-openapi-ui does not read provided yaml configuration

I'm trying to migrate app from autogenerating openapi from existing controllers and model to yaml specification(from which controller interfaces/models will be generated). YAML file is ready, bean OpenAPI providing some information is gone, I set springdoc.packages-to-scan= and tried to point to yaml file using:
springdoc.api-docs.path=/api.yaml and/or springdoc.swagger-ui.url=http://localhost:8080/ofs/api.yaml, but for some reason, while I get updated URL for 'source' yaml file, it is not the source file, it was somehow autogenerated. I see wrong servers, some default title etc.
sole maven dependency is:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
</dependency>
I didn't find any autoconfiguration. I think I see results of some "we will do magic for you" default configuration, but I cannot find anywhere (tutorials/documentation) how to force system to: "don't do anything, use this configuration".
Can someone advice / point me to documentation(specific section) or some tutorial? Or did I get it wrong and in this case I should not use springdoc-openapi-ui at all?

How to debug when Flyway doesn't work on Spring Boot?

I am using Maven and Spring Boot. I run the application using mvn spring-boot:run.
https://flywaydb.org/documentation/plugins/springboot says Flyway should be called on Spring Boot start.
So my pom.xml contains the dependency to Flyway.
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>4.1.2</version>
</dependency>
The first time I ran the Maven command above it downloaded Flyway stuff, so I think the dependency is working.
I have the following files:
./src/main/resources/db/migration/V123__foo.sql
./src/main/resources/application.properties
The above article implied it should "just work", but I don't understand where it would find the JDBC URL to the database. So I added the following to the application.properties file:
flyway.url=jdbc:postgresql://localhost:5432/services?user=postgres&password=postgres
flyway.enabled=true
When Spring Boot starts up (and loads and makes available my web application) there are no logs from Flyway. I think Flyway is ignored.
What can I do? Or, more generally, how would I go about debugging this problem myself?
Nobody has posted an answer so I'll post what I found out.
M. Deinum was indeed correct in their comments to the question, the problem was a lack of a data source.
My original question was what the approach should be to debugging this kind of issue. Obviously one option is to post to stackoverflow :) But I wanted to know how to do it myself.
Spring Boot has a number of classes which look at your code and classpath, and act appropriately. For example, there are classes providing implementations to the rules like "if Flyway is on the path, and there is a data source, then execute Flyway". That rule wasn't getting triggered in my case, because I had no data source.
It's not the case that the code you write calls Spring Boot, it's the other way around, Spring Boot (external to your code) inspects your code and decides what to do based on rules. This architecture is known as action at a distance. The main problem with action at a distance is it's very difficult to debug.
The only real way to find the solution, and it was the way I went about confirming M. Deinum's diagnostic, is to read the Spring Boot source code and understand the annotations which are used to create Spring Boot code.
From the source code to Spring Boot's Flyway integration we see
#ConditionalOnClass(Flyway.class)
#ConditionalOnBean(DataSource.class)
This means "this code will get executed if Flyway is on the classpath, and if there is a DataSource bean available; otherwise it silently won't get executed".
So the answer to the question "how to debug this problem" is that there is no mechanism other than to read the source code of Spring Boot and find out how it works.
If you want to avoid this sort of problem, you have to avoid frameworks which work via "action at a distance", and that includes Spring Boot.

Spring Batch Quick Start not working

I'm trying Spring Batch Quick Start from Spring site (Spring Boot Quick Start) but I can't get it to work:
end() method in SimpleJobBuilder (see job method in BatchConfiguration class) is missing
When I run the main class (removing the reference to end method), Spring Boot starts up (I see the logs in the console) but the job it's not getting executed; from docs around the web I saw that the job should start as soon as the SpringApplication is run
There is something terribly wrong in Spring Batch Quick Start or there's something terribly wrong in what I'm doing?
I think it's useless to publish my code: it's copied from Spring Batch Quick Start...
Thanks for your help!
I think that little sample might be incomplete. For instance you would need #Enable AutoConfiguration in order to get a job to run on start up. There's a more extensive example here, if it helps: https://spring.io/guides/gs/batch-processing/.
In step one of the Spring Batch quick started, the guide asked to add this(the dependency below) into the pom.xml but it errored when there's no version provided. Reason being is that the guide didn't include the parent dependency. So the annotations and the java objects do not know where to look.
I got the quick guide to work by directly including the spring-boot-starter dependency. Then the app ran.. A lot of the spring framework guides seem to assume a strong knowledge in project management and comprehension tool.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>

Spring Roo NoClassDefFoundError

my primary attempt is to build a CRUD app using Roo, following the example here:
https://www.icts.uiowa.edu/confluence/display/ICTSit/Spring+Roo+Tutorial
I am using Roo 1.2.5, Maven 3.1.1, and Spring 3.2.6 on JRE7.
This has been the best tutorial I have found so far. If anyone has a better example, please share!
However, when I execute the project in my Tomcat environment things still break. The primary error from there is:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NoClassDefFoundError: org/springframework/util/MimeType
I have built multiple projects using Roo over the past few days, either from this tutorial or 10 others that all start with the reverse engineer command, and all give me the same type of a NoClassDefFoundError, either with this class or another. I understand this means that my pom.xml is more than likely incorrect, but I am hoping this is an issue with my configuration rather than something all Roo developers have simply accepted as manual maintenance.
Any advice would be tremendous... is it possible that the version of Roo combined with Spring and Maven I am using is simply buggy? I would love to use this framework/toolkit, but am nearing the point where manually writing the scaffolding by hand may be more straightforward.
.... UPDATE:
By adding the following dependency manually, I was able to run the project. However, I want to leave the question open to see if anyone further knows whether this missing jar is a known bug given the version of Spring Roo I am using, or otherwise:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
Thanks!
The best examples are those included in Roo: clinic.roo, pizzashop.roo, etc
Just run Roo and execute any of them as follows:
/_/ |_|\____/\____/ 1.2.4.RELEASE [rev 75337cf]
Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.
roo> script --file clinic.roo
On the other side, the reference doc is a good starting point: http://docs.spring.io/spring-roo/reference/html/
Finally, about java.lang.NoClassDefFoundError: org/springframework/util/MimeType note MimeType class was included in Spring 4 and Roo sets up your project for Spring 3, so you must customize the pom.xml as needed.

Resources