I have upgraded my Spring Boot project to 2.7.4 & Springfox to 3.0.0.
But this resulted in the exception,
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
After doing some research, I added the following config in the application.properties, but the issue was still not fixed.
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Then I found out that, Spring Actuator is causing this issue, and setting the following property fixed the issue.
management.server.port=8082
I don't want to define a custom management port, instead I want it to take the default server port.
Why is Actuator conflicting with Springfox? How do I fix this issue?
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<relativePath />
</parent>
<properties>
<java.version>1.8</java.version>
<spring.cloud-version>2021.0.4</spring.cloud-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
Springfox Swagger Config
#Configuration
#EnableSwagger2
public class SwaggerConfig {
#Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.swagger.io")).paths(PathSelectors.any()).build();
}
}
Springfox has not been maintained for quite some time now. Getting it to work with Spring Boot 2.7 is possible by disabling more recent Spring Boot features but probably not worth your time. It's unlikely to work at all with Spring Boot 3.
You can use Springdoc instead. The migration is usually not much work: https://springdoc.org/migrating-from-springfox.html
Related
I am setting up a Springboot(version 2.0.4) project with maven build to use PostgreSQL database. I want to utilize data-source auto configuration feature of Springboot but it is giving me following errors:
Field dataSource in com.praveen.demo.MyController required a bean of type 'javax.sql.DataSource' that could not be found.
Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required class 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
Bean method 'dataSource' not loaded because #ConditionalOnClass did not find required classes 'javax.transaction.TransactionManager', 'org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType'
In my pom.xml I've dependencies on postgresql and HikariCP as below:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
Also I've in my application.properties file
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb?user=myself&password=mypassword
In my Java file having #RestController annotation , I am injecting DataSource as below:
#Autowired
private DataSource dataSource;
I am following below artcile: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html
I do not want to use JPA. I believe article is not suggesting to use the JPA for auto configuration to work.
I am expecting that Spring boot should auto-configure Data source for the application as I've declared the dependencies and provided the database URL. Still I get errors(as mentioned on top) on starting the application.
Edit-1: I am following below article:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html
Edit-2: Complete 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.praveen</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</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>
Although, I am still confused by the documentation provided at https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html and was expecting that I should not be required to use JPA for auto-configuration to work if I am explicitly declaring a dependency on HikariCP and Postgresql. Closing it for now.
Your pom is fine if you don't want to use JPA.
Define #Bean for Datasource to configure or add property in application.properties spring.datasource.type=com.zaxxer.hikari.HikariDataSource:
#Configuration
public class DbConfig {
#Bean
#ConfigurationProperties("spring.datasource")
public HikariDataSource dataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
}
also change your properties to below:
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username-myself
spring.datasource.password= mypassword
Note: JPA configure for you everything so if not using JPA then you need to configure DataSource by telling about Hikari.
As per reference document 29.1.2 Connection to a Production Database
If you use the spring-boot-starter-jdbc or
spring-boot-starter-data-jpa “starters”, you automatically get a
dependency to HikariCP.
You can bypass that algorithm completely and specify the connection
pool to use by setting the spring.datasource.type property. This is
especially important if you run your application in a Tomcat
container, as tomcat-jdbc is provided by default.
[Tip] Additional connection pools can always be configured manually.
If you define your own DataSource bean, auto-configuration does not
occur.
I am making a new springboot- maven project. The compiler is unable to resolve #RestController when I use below pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
However, when I change the version to 1.5.13, the compiler is able to resolve #RestController
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
I want to be using the latest version of spring boot, and use #RestController.
#RestController doesn't come from org.springframework.boot:spring-boot-starter-web, it comes from org.springframework:spring-web. Different versions of spring-boot-starter-web must probably have some transient dependency that provides it, but it's a bad practice to rely on it. If you use #RestController in your code, you should explicitly require the artifact that provides it:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
since i can't add a comment, i think the maven config is not your problem, check your #Configuration and #SpringBootApplication classes and their path scanning settings
another problem you could have: maybe one of your other dependencies still depends on springboot 1.5, you have to have a clean springboot 2.0 classpath
i run in problems like this as well, so keep on diggin, you'll find it ;-)
I had somewhat a similar issue and it was because I named my class RestController. Once I renamed it Controller, I could import the #RestController packages without issues.
Someone already set up Spring Boot 2 Release and spring-cloud-starter-netflix-zuul?
If I add this dependency in pom file then I have a runtime error: NoSuchFieldError: BINDER_BEAN_NAME.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-zuul</artifactId>
<version>2.0.0.M6</version>
</dependency>
This might be because of dependency management.
Trying adding the dependency management in pom.xml
<properties>
<spring-cloud.version>Finchley.M7</spring-cloud.version>
</properties>
I'm using Spring boot and want to use the starter pom for Spring Integration.
In my POM I have:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This pulls in 4.3.6 versions of Spring Integration jars and 4.3.5 of Spring Framework jars. In one of my own classes I'm trying to use Message:
import org.springframework.integration.Message;
public Object doThings(Message<?> message) {
}
but I can't seem to locate Message. In an older version of Spring integration it was in spring-integration-core.jar but it's not there in this version. Has it moved or has something changed? I've checked the docs and it's still referenced so I assume I'm looking in the wrong place - but core sounds like the place it should be in to me! What am I doing wrong?
A few core concepts of Spring Integration have been merged inside Spring Core between versions 3.0 and 4.0, and org.springframework.integration.Message is one of them.
In your code sample, replacing
import org.springframework.integration.Message;
public Object doThings(Message<?> message) {
}
by
import org.springframework.messaging.Message;
public Object doThings(Message<?> message) {
}
will do the trick.
For a more exhaustive list of affected classes and interfaces, have a look at the 3.0 to 4.0 Spring Integration migration guide
It ok for me with using this version
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.1.9.RELEASE</version>
</dependency>
and
import org.springframework.messaging.Message;
I have project which used JIRA REST Java Client. It worked fine until I tried to integrate it with Spring Boot. Since that I am not able to invoke createWithBasicHttpAuthentication from AsynchronousJiraRestClientFactory without error. I get:
ClassNotFoundException: org.apache.http.util.Args
So I added HttpComponents Core blocking I/O(httpcore) dependency to my pom.xml, but I after that I got
ClassNotFoundException: org.apache.http.nio.NHttpMessageParserFactory
Which I resolved with adding HttpComponents Core non-blocking I/O(httpcore-nio) to pom.xml. Now I have
NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V
I've compared dependency:tree when project has spring boot parent and when it's commented out. It shown me that adding spring boot parent changes versions of my dependencies. You can check diff here( on left without spring boot, on right with spring boot)
It seems that JIRA REST Java Client need older versions of some dependencies.
How can I solve this problem?
pom.xml
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.RELEASE</version>
</parent>
...
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-nio</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
...
I was able to fix runtime in my Spring Boot application by overriding these properties in my pom.xml
<properties>
<httpasyncclient.version>4.0-beta3-atlassian-1</httpasyncclient.version>
<httpclient.version>4.2.1-atlassian-2</httpclient.version>
</properties>
Note that there can be other problems if you decide to use http-client and/or httpassync client in your project (eg. using RestTemplate).
Atlassian should definitely upgrade the dependencies.