Failed to start bean 'documentationPluginsBootstrapper' in spring data rest - java

I am using spring data rest for my application.
I am getting following error and application doesn't get started when I add this method in repository:-
Method:-
#Modifying
#Transactional
#Query("from employee as ft where ft.company.id = ?1")
void deleteAllEmployeeCompany(
#Param("companyId") #RequestParam("companyId") int companyId);
Error:-
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:874) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
How to solve this ?
Updated:-
List of all dependencies:-
[INFO] com.test:test-service:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.4.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.4.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.4.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.1.RELEASE:compile
[INFO] | | \- org.springframework.boot:spring-boot-starter-logging:jar:1.4.1.RELEASE:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.1.7:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.1.7:compile
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.21:compile
[INFO] | | \- org.slf4j:log4j-over-slf4j:jar:1.7.21:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.4.1.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.4.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:1.4.1.RELEASE:compile
[INFO] | | \- org.springframework:spring-aop:jar:4.3.3.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.1.RELEASE:compile
[INFO] | | +- org.apache.tomcat:tomcat-jdbc:jar:8.5.5:compile
[INFO] | | | \- org.apache.tomcat:tomcat-juli:jar:8.5.5:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:4.3.3.RELEASE:compile
[INFO] | +- org.hibernate:hibernate-core:jar:5.0.11.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] | | +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] | | \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] | +- org.hibernate:hibernate-entitymanager:jar:5.0.11.Final:compile
[INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | +- org.springframework.data:spring-data-jpa:jar:1.10.3.RELEASE:compile
[INFO] | | +- org.springframework.data:spring-data-commons:jar:1.12.3.RELEASE:compile
[INFO] | | +- org.springframework:spring-orm:jar:4.3.3.RELEASE:compile
[INFO] | | +- org.springframework:spring-tx:jar:4.3.3.RELEASE:compile
[INFO] | | +- org.springframework:spring-beans:jar:4.3.3.RELEASE:compile
[INFO] | | \- org.slf4j:jcl-over-slf4j:jar:1.7.21:compile
[INFO] | \- org.springframework:spring-aspects:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-rest:jar:1.4.1.RELEASE:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.3:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.3:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.8.3:compile
[INFO] | \- org.springframework.data:spring-data-rest-webmvc:jar:2.5.3.RELEASE:compile
[INFO] | \- org.springframework.data:spring-data-rest-core:jar:2.5.3.RELEASE:compile
[INFO] | \- org.atteo:evo-inflector:jar:1.2.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.1.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.5:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.5:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.5:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] | | \- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | +- org.springframework:spring-web:jar:4.3.3.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.3.3.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-eureka:jar:1.1.0.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-starter:jar:1.1.0.RELEASE:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-context:jar:1.1.0.RELEASE:compile
[INFO] | | | \- org.springframework.security:spring-security-crypto:jar:4.1.3.RELEASE:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-commons:jar:1.1.0.RELEASE:compile
[INFO] | | \- org.springframework.security:spring-security-rsa:jar:1.0.1.RELEASE:compile
[INFO] | | \- org.bouncycastle:bcpkix-jdk15on:jar:1.47:compile
[INFO] | | \- org.bouncycastle:bcprov-jdk15on:jar:1.47:compile
[INFO] | +- org.springframework.cloud:spring-cloud-netflix-core:jar:1.1.0.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-netflix-eureka-client:jar:1.1.0.RELEASE:compile
[INFO] | +- com.netflix.eureka:eureka-client:jar:1.4.6:compile
[INFO] | | +- org.codehaus.jettison:jettison:jar:1.3.7:runtime
[INFO] | | | \- stax:stax-api:jar:1.0.1:runtime
[INFO] | | +- com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:runtime
[INFO] | | +- com.netflix.archaius:archaius-core:jar:0.7.4:compile
[INFO] | | +- javax.ws.rs:jsr311-api:jar:1.1.1:runtime
[INFO] | | +- com.netflix.servo:servo-core:jar:0.10.1:runtime
[INFO] | | | \- com.netflix.servo:servo-internal:jar:0.10.1:runtime
[INFO] | | +- com.sun.jersey:jersey-core:jar:1.19.1:runtime
[INFO] | | +- com.sun.jersey:jersey-client:jar:1.19.1:runtime
[INFO] | | +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] | | | +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] | | | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] | | +- com.google.inject:guice:jar:4.0:runtime
[INFO] | | | +- javax.inject:javax.inject:jar:1:runtime
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:runtime
[INFO] | | \- com.netflix.governator:governator-api:jar:1.12.10:runtime
[INFO] | +- com.netflix.eureka:eureka-core:jar:1.4.6:compile
[INFO] | | +- com.amazonaws:aws-java-sdk-core:jar:1.10.30:runtime
[INFO] | | +- com.amazonaws:aws-java-sdk-ec2:jar:1.10.30:runtime
[INFO] | | +- com.amazonaws:aws-java-sdk-autoscaling:jar:1.9.3:runtime
[INFO] | | +- com.amazonaws:aws-java-sdk-sts:jar:1.9.3:runtime
[INFO] | | +- com.amazonaws:aws-java-sdk-route53:jar:1.9.3:runtime
[INFO] | | +- com.netflix.governator:governator:jar:1.12.10:runtime
[INFO] | | | +- com.netflix.governator:governator-core:jar:1.12.10:runtime
[INFO] | | | \- org.ow2.asm:asm:jar:5.0.4:compile
[INFO] | | \- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:runtime
[INFO] | | +- javax.xml.stream:stax-api:jar:1.0-2:runtime
[INFO] | | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:runtime
[INFO] | +- org.springframework.cloud:spring-cloud-starter-archaius:jar:1.1.0.RELEASE:compile
[INFO] | | \- commons-configuration:commons-configuration:jar:1.8:compile
[INFO] | | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | +- org.springframework.cloud:spring-cloud-starter-ribbon:jar:1.1.0.RELEASE:compile
[INFO] | | +- com.netflix.ribbon:ribbon:jar:2.1.5:compile
[INFO] | | | +- com.netflix.ribbon:ribbon-transport:jar:2.1.5:runtime
[INFO] | | | | +- io.reactivex:rxnetty-contexts:jar:0.4.9:runtime
[INFO] | | | | \- io.reactivex:rxnetty-servo:jar:0.4.9:runtime
[INFO] | | | \- io.reactivex:rxnetty:jar:0.4.9:runtime
[INFO] | | | +- io.netty:netty-codec-http:jar:4.0.27.Final:runtime
[INFO] | | | | +- io.netty:netty-codec:jar:4.0.27.Final:runtime
[INFO] | | | | \- io.netty:netty-handler:jar:4.0.27.Final:runtime
[INFO] | | | \- io.netty:netty-transport-native-epoll:jar:4.0.27.Final:runtime
[INFO] | | | +- io.netty:netty-common:jar:4.0.27.Final:runtime
[INFO] | | | +- io.netty:netty-buffer:jar:4.0.27.Final:runtime
[INFO] | | | \- io.netty:netty-transport:jar:4.0.27.Final:runtime
[INFO] | | +- com.netflix.ribbon:ribbon-core:jar:2.1.5:compile
[INFO] | | +- com.netflix.ribbon:ribbon-httpclient:jar:2.1.5:compile
[INFO] | | | \- com.netflix.netflix-commons:netflix-commons-util:jar:0.1.1:runtime
[INFO] | | +- com.netflix.ribbon:ribbon-loadbalancer:jar:2.1.5:compile
[INFO] | | | \- com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime
[INFO] | | \- io.reactivex:rxjava:jar:1.1.5:compile
[INFO] | +- com.netflix.ribbon:ribbon-eureka:jar:2.1.5:compile
[INFO] | \- com.thoughtworks.xstream:xstream:jar:1.4.2:compile
[INFO] | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:1.4.1.RELEASE:compile
[INFO] | +- org.springframework:spring-messaging:jar:4.3.3.RELEASE:compile
[INFO] | \- org.springframework.amqp:spring-rabbit:jar:1.6.2.RELEASE:compile
[INFO] | +- com.rabbitmq:amqp-client:jar:3.6.3:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:1.1.4.RELEASE:compile
[INFO] | +- com.rabbitmq:http-client:jar:1.0.0.RELEASE:compile
[INFO] | \- org.springframework.amqp:spring-amqp:jar:1.6.2.RELEASE:compile
[INFO] +- com.netflix.hystrix:hystrix-javanica:jar:1.3.16:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | +- org.aspectj:aspectjweaver:jar:1.8.9:compile
[INFO] | +- com.google.guava:guava:jar:18.0:compile
[INFO] | +- com.netflix.hystrix:hystrix-core:jar:1.5.2:compile
[INFO] | | \- org.hdrhistogram:HdrHistogram:jar:2.1.7:compile
[INFO] | \- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- com.netflix.hystrix:hystrix-metrics-event-stream:jar:1.3.16:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.6.0:compile
[INFO] | +- io.swagger:swagger-annotations:jar:1.5.10:compile
[INFO] | +- io.swagger:swagger-models:jar:1.5.10:compile
[INFO] | +- io.springfox:springfox-spi:jar:2.6.0:compile
[INFO] | | \- io.springfox:springfox-core:jar:2.6.0:compile
[INFO] | +- io.springfox:springfox-schema:jar:2.6.0:compile
[INFO] | +- io.springfox:springfox-swagger-common:jar:2.6.0:compile
[INFO] | +- io.springfox:springfox-spring-web:jar:2.6.0:compile
[INFO] | +- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] | +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] | +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] | \- org.mapstruct:mapstruct:jar:1.0.0.Final:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:2.6.0:compile
[INFO] +- io.springfox:springfox-data-rest:jar:2.6.0:compile
[INFO] | \- org.springframework.hateoas:spring-hateoas:jar:0.20.0.RELEASE:compile
[INFO] +- org.liquibase:liquibase-core:jar:3.5.1:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.17:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.34:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.4.1.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:1.4.1.RELEASE:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.1.RELEASE:test
[INFO] | +- junit:junit:jar:4.12:test
[INFO] | +- org.assertj:assertj-core:jar:2.5.0:test
[INFO] | +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | | \- org.objenesis:objenesis:jar:2.1:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.3.0:test
[INFO] | | \- org.json:json:jar:20140107:test
[INFO] | +- org.springframework:spring-core:jar:4.3.3.RELEASE:compile
[INFO] | \- org.springframework:spring-test:jar:4.3.3.RELEASE:test
[INFO] +- com.jayway.jsonpath:json-path:jar:2.2.0:compile
[INFO] | \- net.minidev:json-smart:jar:2.2.1:compile
[INFO] | \- net.minidev:accessors-smart:jar:1.1:compile
[INFO] \- org.reflections:reflections:jar:0.9.10:compile
[INFO] +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] \- com.google.code.findbugs:annotations:jar:2.0.1:compile

I got same issue using springfox-swagger2 and springfox-swagger-ui version(3.0.0), spring-boot version(2.6.2)
The way to resolve this issue is by adding pathmatcher in application. properties or application.yml
for application.properties:
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
for application.yml:
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher

This issue is caused by Spring Fox 3.0.0 not supporting new PathPattern Based Path Matching Strategy for Spring MVC which is now the new default from spring-boot 2.6.0.
There are actually some workarounds for this issue like:
Downgrading spring-boot back to version lower than 2.6.0. I wouldn't recommend that due to major security issues with older versions of spring boot / spring framework (like log4shell or CVE-2022-22965 for example.)
Changing PathPattern matching back to AntPatternMatching in yml, like mentioned by #santhanam.
SpringFox hasn't been updated for a year or so, so I would prefer remove it completely from a project and replace it with maintained springdoc-openapi library. There is a section in springdoc documentation about migration from SpringFox and it's actually very straightforward to perform. And you'll get rid of issues caused by SpringFox completely.

what I found was that spring is using mvcmatchers by default which conflicts with swagger because it uses the antmatchers so we can solve this by
A
change spring to use antmatchers with configuring it
in application.properties
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
B
enabling mvcmatchers in spring creating a config file for swagger to use
create a file for configs of swagger in anywhere you want
put these annotations
#EnableWebMvc
#EnableSwagger2
#Component
public class SwaggersConfigs {
}
C
enableing mvcmatchers in all spring application with putting
#EnableWebMvc
annotation above the main class of spring boot aplication
like this
#EnableWebMvc
#EnableSwagger2
#SpringBootApplication
public class SwaggerDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerDemoApplication.class, args);
}
}
D
use older versions metioned in the other comments

I got same issue using springfox-swagger2 and springfox-swagger-ui
Switching back spring boot version from 2.6.0 to 2.5.2 Solved my issue.
I know rolling back to older versions is not the best way to fix issues but helped me for now.

this works
Springboot version 2.6.0 and higher does not support swagger 2
Remove springfox and swagger 2 dependencies. Add springdoc-openapi-ui dependency instead.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
</dependency>
add this to your application.properties file
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
after that navigate to
http://localhost:8080/swagger-ui/index.html
This worked for me

The reason for the error is swagger and spring-boot The version does not match
Remove All other dependencies and include only below one for swagger
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
Add below Configurations :
For application.properties
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
For application.yml
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher

This solution fixed the issue along with the below property
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
I'm using spring boot 2.6.6

I have got the same issue in spring boot version 1.5.3.RELEASE, but could resolve it by adding guava version 20.0.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

With Spring-Boot 2.6.0 and SpringFox 3.0.0 issue is pathmatcher, you can set pathmach with below property and this issue will be resolved
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher

In addition to setting the matching-strategy property, as mentioned by other answers, I also had to add the below bean to overcome this:
#Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
allEndpoints.addAll(webEndpoints);
allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);
boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
}
private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}
Solution found here.

a work around is to rollback to springfox-swagger2 2.5.0 .

As per official doc, adding below property in yaml resolved the issue for me.
springfox:
documentation:
auto-startup: false

removing old swagger dependencies and config classes.
using new springdoc dependency will help
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.4</version>
</dependency>

Just add this configuration to your application.properties
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER
or if you using yaml file application.yml
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
then Run your application.
You need to edit one part, the base package name. As shown in the screenshot my base package name.
my package name
#Configuration
#EnableSwagger2
public class SwaggerConfig2 {
#Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(true)
.apiInfo(new ApiInfoBuilder()
.title("Swagger Super")
.description("Swagger Description details")
.version("1.0").build())
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.swagger.controller"))
.paths(PathSelectors.any()).build();
}
}
OR
#Configuration
#EnableSwagger2
public class SwaggerConfig2 {
#Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.enable(true)
.apiInfo(new ApiInfoBuilder()
.title("Swagger Super")
.description("Swagger Description details")
.version("1.0").build())
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(PathSelectors.any()).build();
}
}
And the Swagger Dependencies
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
It's working fine
Also, you can define separately
#Configuration
#EnableSwagger2
public class Swagger2UiConfiguration {
#Bean
public Docket api() {
return (new Docket(DocumentationType.SWAGGER_2)).apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any()).build();
}
private ApiInfo apiInfo() {
return (new ApiInfoBuilder()).title("Swagger API").version("1.0").description("Swagger is Awesome").build();
}
}
Note: SNAPSHOT, M1, M2, M3, and M4 releases typically WORK IN PROGRESS. The Spring team is still working on them, Recommend NOT using them.
Note: If want to implement springdoc-openAPI for the new version spring-boot 3 then use the below-following dependency. That specific version would be working with spring boot 3
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>

i got similar issue and it was solved after follow Springboot 2.6.0 / Spring fox 3 - Failed to start bean 'documentationPluginsBootstrapper'
i was using spring 2.6.1 and springfox-swagger2 2.9.2.
"setting spring.mvc.pathmatch.matching-strategy to ant-path-matcher in your application.properties file"

With Spring-Boot 2.6.2 issue is pathmatcher, you can set pathmach with below property in application.properties file and this issue will be resolved
"spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER"

I added #EnableWebMvc as decorator to my SwaggerConfig, which solved to problem.
#EnableWebMvc
public class SwaggerConfig {}
Versions: Sprint 2.6.1 and springfox-swagger* 2.9.2

For me the issue seemed to be attempting to pass in an argument to a controller action (for a controller annotated with RestController) that was not getting resolved.
e.g.
#ResponseBody
#PostMapping(value = "/foo")
com.bestbuy.checkout.domain.Order foo(
Bar justSomeObject
) {

As per : https://github.com/springfox/springfox/issues/2616 solution, I tried adding exclusion to recently added Lettuce library and it is working fine now. Only springfox guava dependency should be coming. As per this question something like below will work:
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>1.3.16</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>

I also had an issue like that in gradle. I solved it by removing all guava dependencies from springfox subdependecies:
implementation('io.springfox:springfox-spi:2.9.2') {
exclude group: 'com.google.guava', module: 'guava'
}
implementation('io.springfox:springfox-schema:2.9.2') {
exclude group: 'com.google.guava', module: 'guava'
}
implementation('io.springfox:springfox-spring-web:2.9.2') {
exclude group: 'com.google.guava', module: 'guava'
}
and implemented guava separately:
implementation('com.google.guava:guava:28.1-jre')
My spring-boot version:
2.5.0-SNAPSHOT

Reducing the version of my project helped me.
Initially, I was using spring 2.6.0 but I moved to 2.5.2 and it solves the issue.

The general reason is that due to the springboot versioning, the default strategy for matching the request path and spring MVC processing mapping has been changed from antpathmatcher to pathpatternparser. This can be resolved by editing the properties.yml and adding
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher

If you are using spring boot 2.6 and trying to use springfox-swagger you will have a hard time.
If you are trying to have swagger documentation just use this dependency
implementation 'org.springdoc:springdoc-openapi-ui:1.6.4'
it will generate the doc for you that you can access using /v3/api-docs and the swagger-ui is accessible using /swagger-ui/index.html
Hope this helps someone.

Change your query to
#Modifying
#Transactional
#Query("from employee as ft where ft.company.id = :companyId")
void deleteAllEmployeeCompany(
#Param("companyId") #RequestParam("companyId") int companyId);
Or with SpEL
#Modifying
#Transactional
#Query("from employee as ft where ft.company.id = ?#{companyId}")
void deleteAllEmployeeCompany(
#Param("companyId") #RequestParam("companyId") int companyId);
Check this https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions

I have a mircoservice environment, and I was adding swagger to all of them. I had the same issue, the solution #Santhanam worked for all the services except one. The service had spring-boot-starter-actuator as a dependency. Problem fixed by removing it.
It seems the config spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER does not affect Spring Actuator auto-generated paths.
For those who tried other answers and still have the problem, the solution is to remove Spring Actuator or to configure it in a way to use ANT_PATH_MATCHER as matching strategy.

I solved the issue easily. What we need to know is that Spinifex is no more up to date For more info click on this link. Nowadays, you can use spring-doc, by remplacing spring-fox dependencies with this dependency :
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.8</version>
</dependency>
then add also this beans :
#Bean
public GroupedOpenApi publicApi() {
return GroupedOpenApi.builder()
.group("springshop-public")
.pathsToMatch("/public/**")
.build();
}
#Bean
public GroupedOpenApi adminApi() {
return GroupedOpenApi.builder()
.group("springshop-admin")
.pathsToMatch("/**")
.build();
}

change spring to use antmatchers with configuring it in application.properties in your spring boot project.
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

I am using 2.7.6 version of spring boot and I was getting the same error. So I found the solution and check this; Failed to start bean ‘documentationPluginsBootstrapper’ – use springdoc-openapi-ui
I added openapi dependency to my pom.xml file:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
Also added matching-strategy to my application.preperties or application.yml file;
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER

I resolve this issue in Spring Boot 2.1.6.RELEASE and Spring Fox 3.0.0 just adding this dependency:
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>

Downgrading the Springboot version from 2.6.0 to 2.5.4 solves the issue, provided the below swagger version
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

Related

Evaluation error (NoSuchMethodError) in Azure ApplicationTokenCredentials when trying to start a VM

I have an Azure VM that I need to remotely control. I'm authenticating using ApplicationTokenCredentials in the expected way;
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client,
tenant,
key,
AzureEnvironment.AZURE);
Then finding my machine:
VirtualMachine vm = Azure
.configure()
.withLogLevel(LogLevel.NONE)
.authenticate(credentials)
.withSubscription(subscription)
.virtualMachines()
.getByResourceGroup(resourceGroup, machineName);
This is essentially the same approach as the official documentation here shows;
https://learn.microsoft.com/en-us/azure/developer/java/sdk/java-sdk-manage-virtual-machines?view=azure-java-stable
This works, authenticates, and sets me up with a VirtualMachine object. I've confirmed that that's what it is and that it's the correct machine that I'm looking to control.
However when I try to start it with the start() method, this happens:
Evaluation error (NoSuchMethodError) at com.microsoft.azure.credentials.ApplicationTokenCredentials.getToken (ApplicationTokenCredentials.java:138).
My dependency tree looks fine. I'm using the newest version (1.35.0) of com.microsoft.azure (and only that) from maven central;
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.35.0</version>
</dependency>
Of course this is the parent dependency and it pulls down a bunch of artifacts. My dependency tree seems fine at a glance though:
+- com.microsoft.azure:azure:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-client-runtime:jar:1.7.0:compile
[INFO] | | \- com.microsoft.rest:client-runtime:jar:1.7.0:compile
[INFO] | | +- com.squareup.retrofit2:retrofit:jar:2.5.0:compile
[INFO] | | +- com.squareup.okhttp3:okhttp:jar:3.12.6:compile
[INFO] | | | \- com.squareup.okio:okio:jar:1.15.0:compile
[INFO] | | +- com.squareup.okhttp3:logging-
interceptor:jar:3.12.2:compile
[INFO] | | +- com.squareup.okhttp3:okhttp-
urlconnection:jar:3.12.2:compile
[INFO] | | +- com.squareup.retrofit2:converter-
jackson:jar:2.5.0:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-
databind:jar:2.9.4:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-
joda:jar:2.10.0:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-
annotations:jar:2.10.0:compile
[INFO] | | \- com.squareup.retrofit2:adapter-rxjava:jar:2.6.2:compile
[INFO] | +- com.microsoft.azure:azure-client-
authentication:jar:1.7.0:compile
[INFO] | | \- com.microsoft.azure:azure-annotations:jar:1.10.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-resources:jar:1.35.0:compile
[INFO] | | \- io.reactivex:rxjava:jar:1.3.8:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-storage:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-network:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-graph-rbac:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-keyvault:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-batch:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
trafficmanager:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-dns:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-redis:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-appservice:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-locks:jar:1.35.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-eventhub:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-cdn:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-sql:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
containerinstance:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
containerregistry:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
containerservice:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-cosmosdb:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-search:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-msi:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-monitor:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-servicebus:jar:1.35.0:compile
[INFO] | \- com.microsoft.azure:azure-mgmt-batchai:jar:1.35.0:compile
[INFO] +- com.microsoft.azure:azure-mgmt-compute:jar:1.35.0:compile
[INFO] | \- com.google.code.gson:gson:jar:2.2.4:compile
At least I don't see anything that stands out as dependency conflict here. I really have no idea how to proceed here.
I ended up setting up a test project with just the VM management and found that working on the same dependencies.
After painstakingly comparing the dependencies between the two, I found one discrepancy; the version of the com.microsoft.azure.adal4j package was 1.6.4 on my test project, and 1.0.0 on my production app.
I have no idea how my production app ended up with an older version of this since all the root azure dependencies are identical, but I added this dependency to my production app, which fixed the issue:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.4</version>
</dependency>

ElasticSearch : setup transport client

I'm new using ElasticSearch Java API, and i want to create the connection with my instance.
I followed the instructions here :
getting started
So i get the following code (as simple as on the exemple ! ) :
TransportClient mClient = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"),
9300));
But I'm facing an issue about importing classes : TransportClient and Settings, that Eclipse cannot find...
Here is the maven import :
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
I tried to search bout this issue but didn't find the solution...
Eclipse found without any problem the PreBuiltTransportClient.
Here is the result of mvn dependency:tee
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # poc ---
[INFO] fr.consortnt:poc:war:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- javax:javaee-web-api:jar:6.0:provided
[INFO] +- org.elasticsearch.client:transport:jar:5.3.0:compile
[INFO] | +- org.elasticsearch:elasticsearch:jar:5.3.0:compile
[INFO] | | +- org.apache.lucene:lucene-core:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-analyzers-common:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-backward-codecs:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-grouping:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-highlighter:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-join:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-memory:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-misc:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-queries:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-queryparser:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-sandbox:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-spatial:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-spatial-extras:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-spatial3d:jar:6.4.1:compile
[INFO] | | +- org.apache.lucene:lucene-suggest:jar:6.4.1:compile
[INFO] | | +- org.elasticsearch:securesm:jar:1.1:compile
[INFO] | | +- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
[INFO] | | +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] | | +- joda-time:joda-time:jar:2.9.5:compile
[INFO] | | +- org.yaml:snakeyaml:jar:1.15:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.8.6:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.6:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.6:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.6:compile
[INFO] | | +- com.tdunning:t-digest:jar:3.0:compile
[INFO] | | +- org.hdrhistogram:HdrHistogram:jar:2.1.6:compile
[INFO] | | \- net.java.dev.jna:jna:jar:4.2.2:compile
[INFO] | +- org.elasticsearch.plugin:transport-netty3-client:jar:5.3.0:compile
[INFO] | | \- io.netty:netty:jar:3.10.6.Final:compile
[INFO] | +- org.elasticsearch.plugin:transport-netty4-client:jar:5.3.0:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.1.7.Final:compile
[INFO] | | +- io.netty:netty-codec:jar:4.1.7.Final:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.1.7.Final:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.7.Final:compile
[INFO] | | +- io.netty:netty-handler:jar:4.1.7.Final:compile
[INFO] | | +- io.netty:netty-resolver:jar:4.1.7.Final:compile
[INFO] | | \- io.netty:netty-transport:jar:4.1.7.Final:compile
[INFO] | +- org.elasticsearch.plugin:reindex-client:jar:5.3.0:compile
[INFO] | | \- org.elasticsearch.client:rest:jar:5.3.0:compile
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] | | +- org.apache.httpcomponents:httpasyncclient:jar:4.1.2:compile
[INFO] | | +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] | | +- commons-codec:commons-codec:jar:1.10:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] | +- org.elasticsearch.plugin:lang-mustache-client:jar:5.3.0:compile
[INFO] | | \- com.github.spullara.mustache.java:compiler:jar:0.9.3:compile
[INFO] | \- org.elasticsearch.plugin:percolator-client:jar:5.3.0:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.7:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] +- taglibs:standard:jar:1.1.2:compile
[INFO] +- jstl:jstl:jar:1.2:runtime
[INFO] +- org.postgresql:postgresql:jar:9.4.1212:compile
[INFO] \- org.hibernate:hibernate-entitymanager:jar:4.2.15.Final:compile
[INFO] +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] +- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO] \- org.hibernate:hibernate-core:jar:4.2.15.Final:compile
[INFO] \- antlr:antlr:jar:2.7.7:compile
Any idea about what happens ?
I'm pretty sure that it's not a problem from maven configuration because I can import from elasticsearch some of classes needed...
Thanks in advance !
I am not an eclipse user for a few years now but this looks like an eclipse / maven configuration issue so I recommend you to review your eclipse configuration with maven.
I say this is a configuration issue because I have an application working with the following maven dependency configuration:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<!-- Log Dependencies required by elasticsearch 5 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
Notice that you don't need to add the org.elasticsearch (first one in your list) dependency as this was used when running elasticsearch embedded which is not supported anymore, but it's possible, if this is your case then leave it there, if you're just building a client you don't need that first dependency.
P.S - If your eclipse/maven configuration is correct then just maybe you forgot to mvn clean install before running your app?

Powermock - java.lang.IllegalStateException: Failed to transform class

Description:
I am trying to test a static method from a class. I am using powerMock (1.6.2) + mockito (1.10.19) for mocking along with Junit4 (4.12) & java8.
Issue:
Getting the error: "Failed to transform class with name com.gs.ops.domain.StaticClass Reason: java.io.IOException: invalid constant type: 18"
Solutions Tried:
Googled threads for issue on with powermock - mockito & java-8
Excluded java assist from powermock and added java assist 3.19.0-GA
Tried different versions of powermock (1.5.4, 1.6.2...)
Below is the exception stack trace:
java.lang.IllegalStateException: Failed to transform class with name com.StaticClass. Reason: java.io.IOException: invalid constant type: 18
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:266)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:145)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassType.getClassFile2(CtClassType.java:203)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:110)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:96)
at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:704)
at javassist.expr.NewExpr$ProceedForNew.setReturnType(NewExpr.java:243)
at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:146)
at javassist.compiler.ast.CallExpr.accept(CallExpr.java:45)
at javassist.compiler.TypeChecker.atVariableAssign(TypeChecker.java:248)
at javassist.compiler.TypeChecker.atAssignExpr(TypeChecker.java:217)
at javassist.compiler.ast.AssignExpr.accept(AssignExpr.java:38)
at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:241)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:329)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:404)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:354)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.Javac.compileStmnt(Javac.java:568)
at javassist.expr.NewExpr.replace(NewExpr.java:206)
at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:418)
at javassist.expr.ExprEditor.loopBody(ExprEditor.java:211)
at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
at javassist.CtClassType.instrument(CtClassType.java:1374)
at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:74)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:251)
... 24 more
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090)
at javassist.bytecode.ConstPool.read(ConstPool.java:1033)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:149)
at javassist.bytecode.ClassFile.read(ClassFile.java:737)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:108)
at javassist.CtClassType.getClassFile2(CtClassType.java:190)
... 49 more
Pom file:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.19.0-GA</version>
</dependency>
Powermock 1.6.3 uses javassist 3.15.2-GA which does not support certain types. Using 3.18.2-GA javassist worked for me. You may want to override dependency in your project.
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
You may face another problem for which the solution lies here Mockito + PowerMock LinkageError while mocking system class
Hope this helps.
So there seems to be issue with javassist (bytecode toolkit) prior to 3.18.2, as there's a resolved JIRA ticket-223.
1 - To find javassist version in your pom.xml, can use mvn dependency task
$ mvn dependency:tree | grep javassist
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
which is used by the powermock-module-junit4-rule ,
[INFO] +- org.powermock:powermock-module-junit4-rule:jar:1.4.9:test
[INFO] | +- org.powermock:powermock-classloading-base:jar:1.4.9:test
[INFO] | \- org.powermock:powermock-core:jar:1.4.9:compile
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
2 - So, updating the javassist version by explicitly to any versions >= 3.18.2 should work.
As, in my case, I am using use 3.20.0-GA
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
Working eg. with scalatest
#PowerMockIgnore(Array("javax.management.*"))
#RunWith(classOf[PowerMockRunner])
#PrepareForTest(Array(classOf[Configurator]))
class LogServiceSpec {
#Test
def initialises_log4j2_on_each_instance_call() {
PowerMockito.mockStatic(classOf[Configurator])
val logService1 = new LogService
PowerMockito.verifyStatic(Mockito.times(1))
Configurator.initialize(Matchers.anyString(), Matchers.eq("log4j.config"))
}
}
This is caused because of the conflict of dependencies. Resolving the dependency conflicts is one way to resolve this issue and the other way is to reorder <dependency></dependency> elements in your pom.xml. Move the powermock dependency declarations to the top of the <dependencies></dependencies> section. This is a complete hack and the right way to resolve it would be to resolve the dependency conflicts.
To identify those conflict you may use the command "mvn dependency:tree". Here is the dependency tree for my application for which I came across this same problem. Notice that there are two dependencies of "javassist" in the tree.
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] | \- org.objenesis:objenesis:jar:2.1:compile
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.4:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.4:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.4:compile
[INFO] | <span style="background-color: #FFFF00">| \- org.javassist:javassist:jar:3.20.0-GA:compile</span>
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.4:compile
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.4:compile
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.4:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.14:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.14:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] | +- org.apache.struts:struts2-core:jar:2.3.16.3-atlassian-6:provided
[INFO] | | \- ognl:ognl:jar:3.0.6:provided
<span style="background-color: #FFFF00">
[INFO] | | \- javassist:javassist:jar:3.11.0.GA:provided</span>
[INFO] | +- com.atlassian:webwork-compat:jar:1.24:provided
[INFO] | +- org.freemarker:freemarker:jar:2.3.16-atlassian-34:provided
[INFO] | | \- logkit:logkit:jar:1.2:provided
[INFO] | +- opensymphony:sitemesh:jar:2.5-atlassian-6:provided
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3.1:provided
[INFO] | +- org.tuckey:urlrewritefilter:jar:4.0.3:provided
[INFO] | +- velocity-tools:velocity-tools:jar:1.2:provided
[INFO] | +- commons-dbutils:commons-dbutils:jar:1.3:provided
[INFO] | +- org.hamcrest:hamcrest-all:jar:1.3:provided
[INFO] | +- com.atlassian.bamboo:atlassian-user-crowd-provider:jar:5.10.0:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-client-rest:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:crowd-integration-client-common:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.security:atlassian-cookie-tools:jar:3.2:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-api:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:embedded-crowd-api:jar:2.7.2:provided
[INFO] | | +- com.atlassian.user:atlassian-user-api:jar:4.1.1:provided
[INFO] | | | \- com.opensymphony.propertyset:api:jar:1.6.0-m1:provided
[INFO] | | +- com.atlassian.user:atlassian-user-ldap:jar:4.1.1:provided
[INFO] | | +- org.acegisecurity:acegi-security:jar:1.0.4:provided
[INFO] | | | \- oro:oro:jar:2.0.8:provided
[INFO] | | \- com.atlassian.crowd:crowd-integration-seraph25:jar:2.7.2:provided
[INFO] | +- javax.xml.stream:stax-api:jar:1.0-2:provided
[INFO] | +- com.atlassian.core:atlassian-core:jar:5.0.2:provided
[INFO] | | \- com.atlassian.image:atlassian-image-consumer:jar:1.0.1:provided
[INFO] | +- org.apache.maven:maven-embedder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-settings:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-plugin-api:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-model-builder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-compat:jar:3.0.4:provided
[INFO] | | +- org.codehaus.plexus:plexus-classworlds:jar:2.4:provided
[INFO] | | +- org.sonatype.sisu:sisu-inject-plexus:jar:2.3.0:provided
[INFO] | | | \- org.sonatype.sisu:sisu-inject-bean:jar:2.3.0:provided
[INFO] | | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:provided
[INFO] | | +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:provided
[INFO] | | +- org.sonatype.plexus:plexus-cipher:jar:1.7:provided
[INFO] | | \- commons-cli:commons-cli:jar:1.2:provided
[INFO] | +- org.apache.maven:maven-model:jar:3.0.4:provided
[INFO] | +- com.octo.captcha:jcaptcha:jar:2.0-alpha-1:provided
[INFO] | +- com.octo.captcha:jcaptcha-api:jar:2.0-alpha-1:provided
[INFO] | +- com.jhlabs:filters:jar:2.0.235:provided
[INFO] | +- org.apache.struts:struts2-sitemesh-plugin:jar:2.1.8.1:provided
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.10:provided
[INFO] | +- com.atlassian.plugins:atlassian-plugins-schema:jar:4.0.5:provided
[INFO] | | \- com.atlassian.plugins:atlassian-plugins-osgi:jar:4.0.5:provided
[INFO] | | +- com.atlassian.plugins:atlassian-plugins-osgi-events:jar:4.0.5:provided
[INFO] | | +- biz.aQute.bnd:biz.aQute.bndlib:jar:2.4.1:provided
[INFO] | | +- org.apache.felix:org.apache.felix.framework:jar:4.2.1:provided
[INFO] | | \- org.twdata.pkgscanner:package-scanner:jar:0.9.5:provided
[INFO] | \- xerces:xercesImpl:jar:2.11.0:provided
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:provided
[INFO] +- junit:junit:jar:4.12:test
[INFO] +- info.cukes:cucumber-java:jar:1.2.4:test
[INFO] | \- info.cukes:cucumber-core:jar:1.2.4:test
[INFO] | +- info.cukes:cucumber-html:jar:0.2.3:test
[INFO] | +- info.cukes:cucumber-jvm-deps:jar:1.0.5:test
[INFO] | \- info.cukes:gherkin:jar:2.12.2:test
[INFO] +- info.cukes:cucumber-junit:jar:1.2.4:test
[INFO] +- com.atlassian.plugins:atlassian-plugins-osgi-testrunner:jar:1.2.3:test
[INFO] | +- org.apache.wink:wink-client:jar:1.1.3-incubating:test
[INFO] | | +- org.apache.wink:wink-common:jar:1.1.3-incubating:test
[INFO] | | | \- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0:test
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.2:test
[INFO] | | \- com.sun.xml.bind:jaxb-impl:jar:2.2.1.1:test
[INFO] | +- commons-io:commons-io:jar:1.4:provided
[INFO] | \- com.atlassian.upm:upm-api:jar:2.15:test
[INFO] +- javax.ws.rs:jsr311-api:jar:1.1.1:provided
[INFO] +- com.google.code.gson:gson:jar:2.2.2-atlassian-1:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.3.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.1:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.0:compile
[INFO] | \- org.apache.httpcomponents:httpcore-nio:jar:4.3:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.1:compile
[INFO] +- org.json:json:jar:20090211:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
I hope this helps.
In my case, a "java.io.IOException: invalid constant type: 18" was caused by multiple versions of javassist libraries in my classpath - both 3.12.1.GA and 3.18.2-GA. The problem disappeared when i removed the older one.
Not really an answer! I got a similar error when running a Maven build with JDK8 and generating Java6 byte code. My pom looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
<maxmem>2000m</maxmem>
<fork>true</fork>
</configuration>
</plugin>
When I reverted to JDK6 I no longer got the error.
In my case JRE System Library --> Execution Environment was set up on JavaSE-1.7, but the only installed JRE was JRE1.8. So it was pointing to java 8 in place of java 7. Once I moved to java 7 it start working fine for me.
This issue is related to a compatibility issue with Java 8. could you execute your tests on java 7 ?
Run "mvn dependency:tree | grep javassist" on terminal. If javaassist dependency is being shown in non test and test libraries. Now you only have to exclude it during runtime for tests. So the way to do this is adding a build plugin on the lines of:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>javassist:javassist</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
</plugins>
Please note the classpathDependencyExcludes might change for you based on your javassist version.

Spring Boot autoconfig is still taking Tomcat Datasource instead HikariCP?

I have my Spring Boot 1.2.5.RELEASE service and I want to use the HikariCP datasource instead of the default tomcat-jdbc. So, according to this Spring Boot Reference I understand I just have to exclude tomcat-jdbc from the classpath and add HikariCP.
So this is my pom.xml:
...
<dependencyManagement>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
</dependencies>
...
maven dependency tree:
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) # myproject-user-manage-webservice ---
[INFO] com.mybusiness.myproject:myproject-user-manage-webservice:jar:0.0.1-SNAPSHOT
[INFO] +- com.mybusiness.myproject:myproject-commons:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- com.mybusiness.myproject:myproject-core:jar:0.0.1-SNAPSHOT:compile
[INFO] | \- com.mybusiness.myproject:myproject-core-commons:jar:0.0.1-SNAPSHOT:compile
[INFO] +- com.mybusiness.myproject:myproject-api:jar:0.0.1-SNAPSHOT:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile (version managed from 2.4.6)
[INFO] | \- com.mybusiness.myproject:myproject-framework:jar:0.0.1-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-security:jar:1.2.1.RELEASE:compile (version managed from 1.2.5.RELEASE)
[INFO] | +- mysql:mysql-connector-java:jar:5.1.34:compile (version managed from 5.1.35)
[INFO] | +- com.mybusiness.framework:despegar-fwk-logging:jar:1.4.148:compile
[INFO] | +- org.jenkins-ci.plugins:testInProgress-client:jar:1.4:compile
[INFO] | | \- org.json:json:jar:20140107:compile
[INFO] | +- commons-io:commons-io:jar:1.3.2:compile
[INFO] | \- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] +- com.mybusiness.myproject:myproject-user-manage-domain:jar:0.0.1-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:1.2.1.RELEASE:compile
[INFO] | | +- org.aspectj:aspectjrt:jar:1.8.4:compile (version managed from 1.8.2)
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.8.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.2.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.2.1.RELEASE:compile
[INFO] | | | +- org.springframework:spring-jdbc:jar:4.1.4.RELEASE:compile
[INFO] | | | \- org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
[INFO] | | +- org.hibernate:hibernate-entitymanager:jar:4.3.7.Final:compile
[INFO] | | | +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] | | | +- org.hibernate:hibernate-core:jar:4.3.7.Final:compile
[INFO] | | | | +- antlr:antlr:jar:2.7.7:compile
[INFO] | | | | \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] | | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | | | +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] | | | \- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] | | +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] | | +- org.springframework:spring-orm:jar:4.1.4.RELEASE:compile (version managed from 4.0.7.RELEASE)
[INFO] | | +- org.springframework.data:spring-data-jpa:jar:1.7.1.RELEASE:compile
[INFO] | | | \- org.springframework.data:spring-data-commons:jar:1.9.1.RELEASE:compile
[INFO] | | \- org.springframework:spring-aspects:jar:4.1.4.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-jwt:jar:1.0.2.RELEASE:compile (version managed from 1.0.3.RELEASE)
[INFO] | | \- org.bouncycastle:bcpkix-jdk15on:jar:1.47:compile
[INFO] | | \- org.bouncycastle:bcprov-jdk15on:jar:1.47:compile
[INFO] | \- org.flywaydb:flyway-core:jar:3.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.2.1.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:1.2.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:1.2.1.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.1.RELEASE:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.14:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.1.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.15:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.15:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.15:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.15:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.4:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.4.4:compile
[INFO] | +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | \- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] | +- org.springframework:spring-core:jar:4.1.4.RELEASE:compile
[INFO] | +- org.springframework:spring-web:jar:4.1.4.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.2.1.RELEASE:compile
[INFO] | \- org.springframework.boot:spring-boot-actuator:jar:1.2.1.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.2.1.RELEASE:test (scope not updated to compile)
[INFO] | +- junit:junit:jar:4.12:test
[INFO] | +- org.mockito:mockito-core:jar:1.10.8:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] | +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] | \- org.springframework:spring-test:jar:4.1.4.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-starter-log4j:jar:1.2.1.RELEASE:compile
[INFO] | +- org.slf4j:jcl-over-slf4j:jar:1.7.8:compile (version managed from 1.7.7)
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.8:compile
[INFO] | +- org.slf4j:slf4j-log4j12:jar:1.7.8:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.7.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:4.1.4.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-core:jar:3.2.5.RELEASE:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:3.2.5.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-web:jar:3.2.5.RELEASE:compile
[INFO] | +- commons-codec:commons-codec:jar:1.6:compile
[INFO] | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- org.springframework.hateoas:spring-hateoas:jar:0.16.0.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.1.4.RELEASE:compile (version managed from 3.2.9.RELEASE)
[INFO] | +- org.objenesis:objenesis:jar:2.1:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.8:compile (version managed from 1.7.7)
[INFO] +- com.zaxxer:HikariCP:jar:2.2.5:compile
[INFO] | \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- ma.glasnost.orika:orika-core:jar:1.4.5:compile
[INFO] | +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] | +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.2_jdk5:compile
[INFO] | \- com.carrotsearch:java-sizeof:jar:0.0.4:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.1.1:compile
[INFO] | +- org.mapstruct:mapstruct:jar:1.0.0.Beta4:compile
[INFO] | +- io.swagger:swagger-annotations:jar:1.5.0:compile
[INFO] | +- io.swagger:swagger-models:jar:1.5.0:compile
[INFO] | +- io.springfox:springfox-spi:jar:2.1.1:compile
[INFO] | | \- io.springfox:springfox-core:jar:2.1.1:compile
[INFO] | +- io.springfox:springfox-schema:jar:2.1.1:compile
[INFO] | +- io.springfox:springfox-swagger-common:jar:2.1.1:compile
[INFO] | +- io.springfox:springfox-spring-web:jar:2.1.1:compile
[INFO] | +- com.google.guava:guava:jar:18.0:compile
[INFO] | +- com.fasterxml:classmate:jar:1.2.0:compile
[INFO] | +- joda-time:joda-time:jar:2.5:compile
[INFO] | +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] | \- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] \- io.springfox:springfox-swagger-ui:jar:2.1.1:compile
So, HikariCP is definitely in tha classpath and tomcat-jdbc is not. But when I launch the service, autoconfig is still creating org.apache.tomcat.jdbc.pool.DataSource instead of a HikariCP one.
What I am doing wrong?
EDIT
This is my application launcher:
#SpringBootApplication
#EnableHypermediaSupport(type = {HypermediaType.HAL})
public class ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(ApplicationRunner.class, args);
}
}
Include Hikari in your pom
Add the following property to your application.yml
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
...
Edit: This answer gives the way to configure Hikari in standard Spring, also valid for Boot. However, as Boot has added greater integration for Hikari since I wrote it, answers like this could be valid and more suitable for Boot.
Just provide the datasource in a #Configuration class:
#Configuration
public class HikariCPConfig {
#Value("${hikari.driverclassname}")
private String driverClassName;
#Value("${hikari.jdbc.url}")
private String jdbcUrl;
#Value("${hikari.username}")
private String userName;
#Value("${hikari.password}")
private String password;
#Value("${hikari.pool.size}")
private int poolSize;
#Bean(destroyMethod = "close")
public DataSource dataSource() {
final HikariDataSource ds = new HikariDataSource();
ds.setMaximumPoolSize(poolSize);
ds.setDriverClassName(driverClassName);
ds.setJdbcUrl(jdbcUrl);
ds.setUsername(userName);
ds.setPassword(password);
return ds;
}
}
Then, in the application.properties file, declare your properties for the datasource, which can be provided by the maven build:
#Hikari
hikari.driverclassname = com.mysql.jdbc.Driver
hikari.jdbc.url = jdbc:mysql://localhost:3306/my_db
hikari.username = ${db.username}
hikari.password = ${db.password}
hikari.pool.size = 5
Then you'll need Spring to scan your HikariCPConfig class, but as you're using #SpringBootApplication which is equivalent to #Configuration #EnableAutoConfiguration and #ComponentScan it shouldn't be a problem.
See also:
Using the #SpringBootApplication annotation
Configuring a datasource in Spring Boot
spring.datasouce.type starts with spring boot 1.3.0, so it won't work on 1.2.5

Can I use only the Transcoder of the Batik library without all other Batik code and dependencies?

I am trying to use the Batik library source, I only want to use the transcoder to convert SVG files to PNG or JPEG only. The distribution version of the Batik Rasterizer is about 55k but when I export the jar file its 7 megs. Can I just use the transcoder and not all the jars in the library? I am loading the jar files in Coldfusion. would it make more sense to just use the distribution version?
This is the dependency tree for batik-transcoder 1.6-1 using mvn dependency:tree -Dverbose:
[INFO] +- batik:batik-transcoder:jar:1.6-1:compile
[INFO] | +- batik:batik-bridge:jar:1.6-1:compile
[INFO] | | +- batik:batik-gvt:jar:1.6-1:compile
[INFO] | | | \- batik:batik-awt-util:jar:1.6-1:compile
[INFO] | | | \- batik:batik-util:jar:1.6-1:compile
[INFO] | | | \- (batik:batik-gui-util:jar:1.6-1:compile - omitted for duplicate)
[INFO] | | +- (batik:batik-bridge:jar:1.6-1:compile - omitted for cycle)
[INFO] | | +- batik:batik-script:jar:1.6-1:compile
[INFO] | | \- batik:batik-svg-dom:jar:1.6-1:compile
[INFO] | | +- batik:batik-dom:jar:1.6-1:compile
[INFO] | | | +- batik:batik-css:jar:1.6-1:compile
[INFO] | | | | \- (batik:batik-util:jar:1.6-1:compile - omitted for duplicate)
[INFO] | | | +- batik:batik-xml:jar:1.6-1:compile
[INFO] | | | | \- (batik:batik-util:jar:1.6-1:compile - omitted for duplicate)
[INFO] | | | \- (xerces:xercesImpl:jar:2.5.0:compile - omitted for conflict with 2.2.1)
[INFO] | | \- batik:batik-parser:jar:1.6-1:compile
[INFO] | | \- (batik:batik-awt-util:jar:1.6-1:compile - omitted for duplicate)
[INFO] | \- fop:fop:jar:0.20.5:compile
[INFO] | +- batik:batik-1.5-fop:jar:0.20-5:compile
[INFO] | +- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] | +- (xalan:xalan:jar:2.4.1:compile - omitted for duplicate)
[INFO] | +- xerces:xercesImpl:jar:2.2.1:compile
[INFO] | \- avalon-framework:avalon-framework:jar:4.0:compile
[INFO] +- batik:batik-gui-util:jar:1.6-1:provided (scope not updated to compile)
[INFO] | \- (batik:batik-ext:jar:1.6-1:provided - omitted for duplicate)
[INFO] +- batik:batik-ext:jar:1.6-1:provided
[INFO] | \- xml-apis:xmlParserAPIs:jar:2.0.2:provided
[INFO] +- rhino:js:jar:1.5R4.1:provided
[INFO] \- xalan:xalan:jar:2.4.1:provided (scope not updated to compile)
If you use maven you could set some dependencies to <scope>provided</scope>
For example I could exlude these without problems, which saved me ca. 1.6MB:
<dependencies>
...
<dependency>
<groupId>batik</groupId>
<artifactId>batik-gui-util</artifactId>
<version>1.6-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>batik</groupId>
<artifactId>batik-ext</artifactId>
<version>1.6-1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.5R4.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
It seems that these are the biggest dependencies:
http://repo.maven.apache.org/maven2/xerces/xercesImpl/2.2.1/xercesImpl-2.2.1.jar (816 KB at 851.9 KB/sec)
http://repo.maven.apache.org/maven2/xalan/xalan/2.4.1/xalan-2.4.1.jar (1007 KB at 479.7 KB/sec)
http://repo.maven.apache.org/maven2/fop/fop/0.20.5/fop-0.20.5.jar (1485 KB at 1011.7 KB/sec)
http://repo.maven.apache.org/maven2/batik/batik-1.5-fop/0.20-5/batik-1.5-fop-0.20-5.jar (2063 KB at 936.0 KB/sec)
Not exactly sure what you want to accomplish, but ProGuard will let you filter classes in jars that aren't used by your code.

Categories