Failed to configure Datasource on spring data jpa dependency? - java

I have a client application with a class that uses Specification, therefore I need a spring data jpa dependency. I know that the Boot dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
...throws an error (Failed to configure a Datasource...) at startup if you include the dependency without a Datasource configured. However, I still get the error when I use this dependency (so just Spring, no Boot) when I import my client in a Spring Boot application when the client uses this dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
Why do I still get this error? I know I can suppress the warning with a property (exclude DataSourceAutoConfiguration) or annotation, but I would prefer not to, and don't really understand why I get this error from Spring. In my understanding, Boot is opiniated throws this error to inform me of missing config, but I thought the vanilla Spring dependency would not do this. I can't find any info on expected behavior on the non-starter dependency, just on the starter dependency.

In spring boot 2.7.3 I didn't find this problem.

Related

How to find out which dependency version I should use?

I'm implementing a new feature in my project, in this case replacing the resttemplate with the webclient. I put this dependency in my pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>???</version>
</dependency>
I used the mvn dependecy:tree command to find out which version of spring-web was current and I verified that it was 3.2.8-RELEASE. How to find out which spring-boot-starter-webflux version I should use in my project's maven so I don't have dependency issues like this: java.lang.NoClassDefFoundError: org/springframework/http/client/reactive/ClientHttpConnector
In other words, how do I find out which version of spring-boot-starter-webflux is compatible with the version of spring-web I'm using?
if I omit the version, when building, I get the error dependencies.dependency.versin is missing.
Spring Boot includes dependency management tools to help solve this problem. If you're using any Spring Boot dependencies, the versions of all your Spring and Spring Boot dependencies should ideally be managed by Spring Boot.
A simple way to do this is to apply the Spring Boot BOM (Bill of Materials) in your Maven dependency management.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Replace the version here with the version of Spring Boot that you want to use. You can then omit the version number from any other Spring or Spring Boot dependencies.
The Spring Boot team maintains the bill of materials so that it provides compatible versioning for all the Spring and Spring Boot components as well as other libraries that the Spring framework depends on.
You can find more information in the docs here: https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.dependency-management
If you would like to refer to Spring's version compatibility table manually, it's published in the Spring Boot docs. For example, you can find the compatible dependency versions for the current version of Spring Boot here: https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html
A good place to start if you're trying to identify the compatible Spring Boot version for an existing dependency is to compare their release dates. Look for a Spring Boot version that was released around the same time as your dependency. Then you can look at the compatibility table for that Spring Boot version. By using that method, I couldn't find a version of Spring Boot that's compatible with spring-web 3.2.8. That version of spring-web is over 8 years old and predates the first release of Spring Boot. You should upgrade it, if you can.

The last Spring boot validation not working

I'm a beginner in spring boot and I found a problem with validation It doesn't work and I tried spring validation also hibernate dependency. I have the last version of spring boot 2.7.2
I add
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency>
to my pom.xml but when I add #NotNull to my bean gave me an error, and showed me there's not a #NonNull Annotation.
I faced the same issue. In my case, there was a problem with my pom. I had a dependency on the hibernate-validator. So I removed and worked for me.

Unable to upgrade swagger2 version from 2.7.0 to 3.00 in Spring REST API(regular Spring not sprint boot)

My project is working fine with swagger2 version 2.7.0.not spring boot(spring mvc only)
I am going to upgrade it 3.0.0 but it's giving plugin errors.
java.lang.nosuchMethodError:org.springframework.plugin.core.pluginRegistry.getPluginFor(Ljava/lang/Object;)Ljava/util/Optional;
My config as below:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Update: As mentioned in https://github.com/springfox/springfox
Step 2 : Add #EnableOpenApi for open API (and #EnableSwagger2WebMvc or #EnableSwagger2WebFlux for older versions)
I added #EnableSwagger2WebMvc in class ,Then it's asking dependency of springfox-swagger2,
as this coming from :
http://springfox.github.io/springfox/javadoc/snapshot/springfox/documentation/swagger2/annotations/EnableSwagger2WebMvc.html
which is part of springfox-swagger2 dependency
Hence I am confused what to do..
can you please help cleaner approach with steps .
If I don't use #EnableSwagger2WebMvc/EnableSwagger2
Swagger is not getting loaded
Not sure if you are using Spring Boot, or regular Spring flavor, but have you followed the migration instructions posted here?
https://github.com/springfox/springfox
Remove explicit dependencies on springfox-swagger2
Remove any #EnableSwagger2... annotations
Add the springfox-boot-starter (Spring boot) or springfox-oas(Spring MVC) dependency
Check if you do not rely on removed dependecy on guava
If you are using WebMvc but you don't use the #EnableWebMvc annotation yet, add this annotation (Spring boot).

Missing artifact net.sf.ha-jdbc:ha-jdbc:jar:3.0.0-rc-1

We are trying to switch databases for our Spring boot application, in case one fails. We are using hibernate as our ORM. So we found this link Primary/Secondary failover DataSource in Spring Boot, which redirected to Using HA-JDBC with Spring Boot.
But when we tried to add the dependency for HA-JDBC, we were getting error like Missing artifact net.sf.ha-jdbc:ha-jdbc:jar:3.0.0-rc-1, this was the location MVNRepository. We tried with all the versions but the error is same. We tried cleaning the project and updating the project but the error is still there.
This is the dependency
<!-- https://mvnrepository.com/artifact/net.sf.ha-jdbc/ha-jdbc -->
<dependency>
<groupId>net.sf.ha-jdbc</groupId>
<artifactId>ha-jdbc</artifactId>
<version>3.0.0-rc-1</version>
</dependency>

Spring Boot Properties Migrator

I'm trying to run an application(spring boot v1.5.9.0) with dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-properties-migrator</artifactId>
<scope>runtime</scope>
</dependency>
and getting this error:
org.springframework.boot.SpringApplication - Application startup failed
java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/source/ConfigurationPropertySources
this error, apparently, did not occur before. How do I make the migrator work?
Do I have to change the spring-boot version to 2x before running the migrator?
If so, i don't really get the migrator usage.
As its scope is runtime - I have to make the app run before including it - which means I have to solve all the errors without migrator's advice? What do I use it for afterwards?
You've stated that you're running spring boot v1.5.9.0
It doesn't make sense to run the properties migrator with spring boot 1.5.x. Its primary intention is to "assist" in properties migrations that have changed during migration of spring boot 1.x to spring boot 2.x
As for the error, this specific class is available only since spring boot 2.0. See the comment #since in the sourcefile
In your project, application.properties or application.yml is present or not? Spring boot is auto-configuration. I think those properties will be expecting..Also check what are the annotations used in Spring boot main class..Share that Spring boot main class as well..will check

Categories