Error while deploying spring boot application on Weblogic server - spring-boot

Facing the issue since I have added Hateoas dependency to my Spring boot project and deploying on weblogic server 12c
Error starting ApplicationContext. To display the conditions report
re-run your application with 'debug' enabled. 2020-01-09 14:18:53,591
ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter
[[STANDBY] ExecuteThread: '3' for queue:
'weblogic.kernel.Default (self-tuning)']
APPLICATION FAILED TO START
Description:
Parameter 0 of method linkDiscoverers in org.springframework.hateoas.config.HateoasConfiguration required a
single bean, but 15 were found:
- modelBuilderPluginRegistry: defined in null
- modelPropertyBuilderPluginRegistry: defined in null
- typeNameProviderPluginRegistry: defined in null
- documentationPluginRegistry: defined in null
- apiListingBuilderPluginRegistry: defined in null
- operationBuilderPluginRegistry: defined in null
- parameterBuilderPluginRegistry: defined in null
- expandedParameterBuilderPluginRegistry: defined in null
- resourceGroupingStrategyRegistry: defined in null
- operationModelsProviderPluginRegistry: defined in null
- defaultsProviderPluginRegistry: defined in null
- pathDecoratorRegistry: defined in null
- relProviderPluginRegistry: defined by method 'relProviderPluginRegistry' in class path resource
[org/springframework/hateoas/config/HateoasConfiguration.class]
- linkDiscovererRegistry: defined in null
- entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry' in class path resource
[org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class]
Action:
Consider marking one of the beans as #Primary, updating the consumer to accept multiple beans, or using #Qualifier to identify the
bean that should be consumed
<09-Jan-2020, 2:18:53,633 PM IST> ' available: expected single
matching bean but found 15:
modelBuilderPluginRegistry,modelPropertyBuilderPluginRegistry,typeNameProviderPluginRegistry,documentationPluginRegistry,apiListingBuilderPluginRegistry,operationBuilderPluginRegistry,parameterBuilderPluginRegistry,expandedParameterBuilderPluginRegistry,resourceGroupingStrategyRegistry,operationModelsProviderPluginRegistry,defaultsProviderPluginRegistry,pathDecoratorRegistry,relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type
'org.springframework.plugin.core.PluginRegistry' available: expected single
matching bean but found 15:
modelBuilderPluginRegistry,modelPropertyBuilderPluginRegistry,typeNameProviderPluginRegistry,documentationPluginRegistry,apiListingBuilderPluginRegistry,operationBuilderPluginRegistry,parameterBuilderPluginRegistry,expandedParameterBuilderPluginRegistry,resourceGroupingStrategyRegistry,operationModelsProviderPluginRegistry,defaultsProviderPluginRegistry,pathDecoratorRegistry,relProviderPluginRegistry,linkDiscovererRegistry,entityLinksPluginRegistry
at org.springframework.beans.factory.config.DependencyDescriptor.resolveNotUnique(DependencyDescriptor.java:220)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1265)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:874)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:778)
Truncated. see log file for complete stacktrace
>
<09-Jan-2020, 2:18:53,674 PM IST>
<09-Jan-2020, 2:18:53,775 PM IST>
<09-Jan-2020, 2:18:53,834 PM IST>
<09-Jan-2020, 2:18:53,981 PM IST>
<09-Jan-2020, 2:18:53,988 PM IST>
<09-Jan-2020, 2:18:53,992 PM IST>
<09-Jan-2020, 2:18:54,0 PM IST>
POM.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.bt</groupId>
<artifactId>Some project</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>some Project</name>
<description>REST enabled adapter to communicate with tetProject database</description>
<repositories>
<repository>
<id>some Repo</id>
<name><xyz.some.name></name>
<url><xyz.some.url></url>
</repository>
</repositories>
<properties>
<java.version>1.8</java.version>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>commonlibs.com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>commonlibs.com.bea.core</groupId>
<artifactId>com.bea.core.datasource6_1.7.0.0</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>commonlibs.com.bea.core.utils</groupId>
<artifactId>com.bea.core.utils.wrapper_1.4.0.0</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
<version>1.2.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>Some project</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

Spring is telling you the problem
org.springframework.hateoas.config.HateoasConfiguration required a single bean,
but 15 were found:
Which means that there are 15 methods that return a bean that fits HateoasConfiguration.
Who are those bastards?
Spring continues right after with the list:
- modelBuilderPluginRegistry: defined in null
- modelPropertyBuilderPluginRegistry: defined in null
- typeNameProviderPluginRegistry: defined in null
- documentationPluginRegistry: defined in null
- apiListingBuilderPluginRegistry: defined in null
- operationBuilderPluginRegistry: defined in null
- parameterBuilderPluginRegistry: defined in null
- expandedParameterBuilderPluginRegistry: defined in null
- resourceGroupingStrategyRegistry: defined in null
- operationModelsProviderPluginRegistry: defined in null
- defaultsProviderPluginRegistry: defined in null
- pathDecoratorRegistry: defined in null
- relProviderPluginRegistry: defined by method 'relProviderPluginRegistry'
in class path resource
[org/springframework/hateoas/config/HateoasConfiguration.class]
- linkDiscovererRegistry: defined in null
- entityLinksPluginRegistry: defined by method 'entityLinksPluginRegistry'
in class path resource
[org/springframework/hateoas/config/WebMvcEntityLinksConfiguration.class]
The list might be not so clear or familiar as it might be that some of these methods are defined by the framework.
So what can be done?
Spring is suggesting a solution:
Action:
Consider marking one of the beans as #Primary,
updating the consumer to accept multiple beans,
or using #Qualifier to identify the bean that should be consumed
Does it mean that I need to reconfigure my #Beans?
Not necessarily. First try to see if someone else faced the same problem.
You may find the solution there.

Related

MASM0015, jaxws.HandlerTubeFactory doesn't implement dev.TubeFactory interface intellij

I tried to create a simple webservice that a client call to a server. But when i run this main from client:
HelloService service = new HelloService();
Hello hello = service.getHelloPort();
System.out.println(hello.greeting("root", "123"));
It's throw this exception:
Exception in thread "main" java.lang.RuntimeException: MASM0015: Class [ com.sun.xml.ws.assembler.jaxws.HandlerTubeFactory ] does not implement [ com.sun.xml.internal.ws.assembler.dev.TubeFactory ] interface
at com.sun.xml.internal.ws.assembler.TubeCreator.<init>(TubeCreator.java:63)
at com.sun.xml.internal.ws.assembler.TubelineAssemblyController.initializeTubeCreators(TubelineAssemblyController.java:116)
at com.sun.xml.internal.ws.assembler.TubelineAssemblyController.getTubeCreators(TubelineAssemblyController.java:79)
at com.sun.xml.internal.ws.assembler.MetroTubelineAssembler.createClient(MetroTubelineAssembler.java:103)
at com.sun.xml.internal.ws.client.Stub.createPipeline(Stub.java:328)
at com.sun.xml.internal.ws.client.Stub.<init>(Stub.java:295)
at com.sun.xml.internal.ws.client.Stub.<init>(Stub.java:228)
at com.sun.xml.internal.ws.client.Stub.<init>(Stub.java:243)
at com.sun.xml.internal.ws.client.sei.SEIStub.<init>(SEIStub.java:84)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getStubHandler(WSServiceDelegate.java:814)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:803)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:436)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:404)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:386)
at javax.xml.ws.Service.getPort(Service.java:119)
at com.example.webclient.HelloService.getHelloPort(HelloService.java:72)
at com.example.webclient.HelloClient.main(HelloClient.java:6)
The code that error are:
Hello hello = service.getHelloPort();
And the getHelloPort() function:
#WebEndpoint(name = "HelloPort")
public Hello getHelloPort() {
return super.getPort(new QName("http://webserver.example.com/", "HelloPort"), Hello.class);
}
Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Prob6</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Prob6</name>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<junit.version>5.8.2</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
I got the same problem here and follow this but still can't solve it
MASM0015 ; Webservice HandlerTubeFactory exception
Please help me! Thanks!
Which application server are you using?
If this is weblogic 12c, then in my case the issue was solved as described here MASM0015 ; Webservice HandlerTubeFactory exception
Also try to exclude the JAX-WS dependencies, they may be make some mess, if you really try to solve this problem for Oracle WebLogic. My variant is working when I use the Java8 default JAX-WS implementation in the combination with the given Weblogic client library.

Spring Boot Configuration Bean behaves different at Windows and Linux

I am using openjdk14 and have interesting problem here. I have reactive project and use spring security and spring session modules. I have created my WebSessionManager as described here. (https://docs.spring.io/spring-session/docs/current/reference/html5/#websession-how)
#Configuration(proxyBeanMethods = false)
#Slf4j
public class SpringWebSessionConfiguration {
#Autowired(required = false)
private WebSessionIdResolver webSessionIdResolver;
#Autowired
private ConfigurableApplicationContext context;
#Bean(WebHttpHandlerBuilder.WEB_SESSION_MANAGER_BEAN_NAME)
public WebSessionManager webSessionManager(ReactiveSessionRepository<? extends Session> repository) {
log.info("line 1");
...
return manager;
}
}
Problem
When I try to compile and run in my local computer (windows 10), my bean is created successfully and I see "line 1" log, so everything is fine. But when i try to compile and run in linux (centos 8) instead, my bean is not created so i cannot see "line 1" log.
Here is the windows log
2020-12-08 17:36:51.371 DEBUG 8368 --- [ main]
o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition
for bean 'webSessionManager' with a different definition: replacing
factoryBeanName=org.springframework.session.data.redis.config.annotation.web.server.RedisWebSessionConfiguration;
factoryMethodName=webSessionManager; initMethodName=null;
destroyMethodName=(inferred); defined in class path resource
[org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfiguration.class]]
factoryBeanName=springWebSessionConfiguration;
factoryMethodName=webSessionManager; initMethodName=null;
destroyMethodName=(inferred); defined in class path resource
[com/yte/apigateway/logout/configuration/SpringWebSessionConfiguration.class]]
here is the linux log
2020-12-08 17:39:40.750 DEBUG 1700 --- [ main]
o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition
for bean 'webSessionManager' with a different definition: replacing
factoryBeanName=springWebSessionConfiguration;
factoryMethodName=webSessionManager; initMethodName=null;
destroyMethodName=(inferred); defined in class path resource
[com/yte/apigateway/logout/configuration/SpringWebSessionConfiguration.class]]
factoryBeanName=org.springframework.session.data.redis.config.annotation.web.server.RedisWebSessionConfiguration;
factoryMethodName=webSessionManager; initMethodName=null;
destroyMethodName=(inferred); defined in class path resource
[org/springframework/session/data/redis/config/annotation/web/server/RedisWebSessionConfiguration.class]]
Linux and Windows are picking different configuration as you can see in logs. Has anyone encountered a similar error before ? It think it must be bug on java. How can I report this? Would you try same configuration if possible to be sure?
Here are my dependencies
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
...
<properties>
<java.version>14</java.version>
<spring-cloud.version>Hoxton.SR5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gateway-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>

Could not resolve placeholder(java.lang.IllegalArgumentException: )

I can't set properties in the application.properties that would then be integrated via #Value
server.port=8099
spring.data.mongodb.database=mongo-spring
spring.data.mongodb.username=root
spring.data.mongodb.password=root
#spring.data.mongodb.host=192.168.99.100
spring.data.mongodb.host=192.168.99.109
spring.data.mongodb.port=27017
#spring.data.mongodb.uri=mongodb://192.168.99.100:27017/mongo-spring
#spring.data.mongodb.repositories.enabled=true
############################################
#--------reCaptcha Google-----------------
#############################################
#Site key - Use this in the HTML code your site serves to users.
#Secret key - Use this for communication between your site and Google. Be sure to keep it a secret.
apiUrl=https://www.google.com/recaptcha/api/siteverify
api.prefix=/api/**
header.cors.origins.allow=http://10.0.0.1:8080 , http://10.10.8.2:8080
header.cors.methods.allow=GET, PUT, POST
#Configuration
public class CorsGlobalConfiguration {
#Value("${api.prefix}")
private String apiPrefix;
#Value("${header.cors.origins.allow}")
private String [] headerCorsOriginsAllow;
#Value("${header.cors.methods.allow}")
private String [] headerCorsMethodsAllow;
#Bean
public WebMvcConfigurer corsConfig() {
return new WebMvcConfigurer() {
#Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(apiPrefix)
.allowedOrigins(headerCorsOriginsAllow)
.allowedMethods(headerCorsMethodsAllow);
}
};
}
}
------------------------------------------------------------------------------- Test set: com.spring.mongo.SpringMongoApplicationTests
------------------------------------------------------------------------------- Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.081
s <<< FAILURE! - in com.spring.mongo.SpringMongoApplicationTests
contextLoads Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'corsGlobalConfiguration': Injection of
autowired dependencies failed; nested exception is
java.lang.IllegalArgumentException: Could not resolve placeholder
'api.prefix' in value "${api.prefix}" Caused by:
java.lang.IllegalArgumentException: Could not resolve placeholder
'api.prefix' in value "${api.prefix}"
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.spring.mongo</groupId>
<artifactId>spring-mongo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-mongo</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<version.mapstruct>1.3.0.Final</version.mapstruct>
<version.apache.maven.plugins>3.8.1</version.apache.maven.plugins>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${version.mapstruct}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.apache.maven.plugins}</version>
<groupId>org.apache.maven.plugins</groupId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${version.mapstruct}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Update-1
I converted the application.properties in the application.in YML format.
An error , disappeared.
But now in the development environment, I can't view the value of a variable by clicking on the #Value expression
And I get another error during an application.
2020-08-07 22:35:15.244 WARN 48300 --- [ main]
ConfigServletWebServerApplicationContext : Exception encountered
during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class
[com.spring.mongo.SpringMongoApplication]; nested exception is
java.io.FileNotFoundException: class path resource
[application.properties] cannot be opened because it does not exist
2020-08-07 22:35:15.262 ERROR 48300 --- [ main]
o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class
[com.spring.mongo.SpringMongoApplication]; nested exception is
java.io.FileNotFoundException: class path resource
[application.properties] cannot be opened because it does not exist
I added into pom.xml
pom.xml
<build>
<resources>
<resource>
<directory>config</directory>
<targetPath>${project.build.outputDirectory}</targetPath>
<includes>
<include>application.yml</include>
</includes>
</resource>
</resources>
Now, I again get the error:
java.lang.IllegalArgumentException: Could not resolve placeholder
Why?
The encoding all project is UTF-8.
Everything worked before. Now the #Value annotation doesn't work
Does anybody have any ideas?

spring boot #repository bean from Maven dependency not found

I'm working on multiple Spring Boot projects using spring-data-mongoDB (w/o JPA). One that contains the common (udc-common) components, repositories and services and others (eg udc-gateway) that use these components. the udc-common library is declared as a maven dependency in the other projects.
(you'll find enclosed the maven detailed configurations at the end of this post)
Environment structure
udc_common project
udc_common.models
udc_common.repositories
udc_common.services
udc_common.interfaces
udc_gateway project
udc_gateway.controllers
udc_gateway ....
gatewayApplication.java
gateway pom.xml
<dependency>
<groupId>org.open_si</groupId>
<artifactId>udc-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
in the udc-gateway project I have a rest controller thats refers to a udc-comm SampleService. When running it I face an error
Parameter 0 of constructor in org.open_si.udc_common.services.SampleService required a bean of type 'org.open_si.udc_common.repositories.SampleRepository' that could not be found.
the coding organization is :
the controller (SamplesController) belongs to the gateway project
the service (SampleService) and its repository (SampleRepository) belong to the common project being declared as maven dependency in the gateway project
Obviously the SampleService injection does work but its SampleRepository dependency doesn't. As the common package is an external one I've set the #componentscan accordingly in the gateway app main class
tryed
#ComponentScan("org.open_si.udc_common")
and
#ComponentScan({
"org.open_si.udc_common.repositories",
"org.open_si.udc_common.services"
})
the SamplesController (gateway project) code excerpt related for the SampleService is
#RestController
#RequestMapping("/samples")
public class SamplesController {
#Autowired
private SampleService service;
......
the SampleService (common project) is
#Service
#EnableMongoRepositories
public class SampleService {
#Autowired
private SampleRepository sr;
void insert(BaseSampleEntity sample) {
this.sr.insert(sample);
}
public void delete(BaseSampleEntity sample) {
this.sr.delete(sample);
}
.....
or also tryed
#Service
#EnableMongoRepositories
public class SampleService {
private final SampleRepository sr;
public SampleService(SampleRepository repository) {
sr = repository;
}
void insert(BaseSampleEntity sample) {
this.sr.insert(sample);
}
public void delete(BaseSampleEntity sample) {
this.sr.delete(sample);
}
and the SampleRepository (common project) is
// #Repository (JPA only)
public interface SampleRepository extends MongoRepository<BaseSampleEntity, String> {
List<BaseSampleEntity> findByNodeUuid(String Uuid, Sort sort, Pageable pageable);
List<BaseSampleEntity> findByFieldUuid(String Uuid, Sort sort, Pageable pageable);
so the raised exception
Parameter 0 of constructor in org.open_si.udc_common.services.SampleService required a bean of type 'org.open_si.udc_common.repositories.SampleRepository' that could not be found.
leads me thinking that something is wrong in the spring boot IOC process. Any idea ?
thanks in advance for your help.
udc-common pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.open_si</groupId>
<artifactId>udc-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>UDC common</name>
<packaging>jar</packaging>
<description>Common resources for Universal Data Collector</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- <source>1.8</source>-->
<!-- <target>1.8</target>-->
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
udc-gateway pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.open_si</groupId>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Gateway</name>
<description>Gateway for UDC project</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.open_si</groupId>
<artifactId>udc-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-oauth2-client</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-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>
Try adding below annotation in the spring boot main application class (ie. class annotated with SpringBootApplication - GateWayApplication.java)
#EnableMongoRepositories(basePackages = "org.open_si.udc_common")
#ComponentScan("org.open_si.udc_common.services")
#EntityScan(basePackages ="org.open_si.udc_common.models")
Also, as you mentioned you don't need to annotate repository class with #Repository as this is already managed by spring data
UPDATE:
#SpringBootApplication itself has ComponentScan annoation embedded to it, so it automatically scans all the classes under all the subdirectories.
Hope you have the directory structure somewhat similar to
com.example
--controllers
-- SamplesController
--service
-- SampleService
SampleApplication (this is the class that contains #SpringBootApplication & #EnableMongoRepositories)
Mb you need to add the Spring Data dependency to Maven
As suggested by Kumar V adding
#ComponentScan("org.open_si.udc_common.services")
#EnableMongoRepositories(basePackages = {"org.open_si.udc_common.repositories"})
In the gateway.application.java did the trick.
Unfortunately due to the org.open_si.udc_common.services import, I faced a new issue :
when sending a request against the SamplesController I get an HTTP 404 error.
When removing the ComponentScan of udc-common-services (and the reference to the SampleService in the controller) everythink is ok.
Springs does make some stuff under the wood that I don't understand.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityInterceptor' defined in class path resource

I need to sign using SOAP request and due to that, I need to use ws-security dep from Spring.
#ComponentScan(basePackages = {"mk.softnet.wsdl","mk.softnet.Porting"})
public class SoapConfig extends WsConfigurerAdapter {
#Bean
public XwsSecurityInterceptor securityInterceptor() {
XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
securityInterceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
securityInterceptor.setCallbackHandler(callbackHandler());
//Security Policy -> securityPolicy.xml
return securityInterceptor;
}
#Bean
SimplePasswordValidationCallbackHandler callbackHandler() {
SimplePasswordValidationCallbackHandler callbackHandler = new SimplePasswordValidationCallbackHandler();
// TODO #rap: Use real username and passwords
callbackHandler.setUsersMap(Collections.singletonMap("user", "password"));
return callbackHandler;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>mk.softnet</groupId>
<artifactId>Porting</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Porting</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>5.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>mk.softnet.wsdl</generatePackage>
<schemas>
<schema>
<url>WDSL_URL
</url>
</schema>
</schemas>
</configuration>
</plugin>
</plugins>
</build>
</project>
Test set: mk.softnet.Porting.PortingApplicationTests
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.79 s <<< FAILURE! - in mk.softnet.Porting.PortingApplicationTests
contextLoads(mk.softnet.Porting.PortingApplicationTests) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityInterceptor' defined in class path resource [mk/softnet/Porting/config/SoapConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor]: Factory method 'securityInterceptor' threw exception; nested exception is java.lang.NoClassDefFoundError: com/sun/xml/wss/XWSSecurityException
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor]: Factory method 'securityInterceptor' threw exception; nested exception is java.lang.NoClassDefFoundError: com/sun/xml/wss/XWSSecurityException
Caused by: java.lang.NoClassDefFoundError: com/sun/xml/wss/XWSSecurityException
Caused by: java.lang.ClassNotFoundException: com.sun.xml.wss.XWSSecurityException
I tried to change version but did not get any success.
You need to add com.sun.xml.wss dependency.
Add this dependency to the pom.xml :
<dependency>
<groupId>com.sun.xml.wss</groupId>
<artifactId>xws-security</artifactId>
<version>3.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>xmldsig</artifactId>
<groupId>javax.xml.crypto</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
Look at the pom for spring-ws-security - 2.2.0 RELEASE

Resources