Can't use #Value and #Autowired with properties in Spring Cloud Configuration Server - spring-cloud-config

I have a SpringBoot 1.5.12 app using the Edgware.SR3 Spring Cloud release.
The following code:
#Configuration
public class HmlConfig
{
#Value("${jms.destination.name}")
...
}
...
#RestController
#RequestMapping("/api")
public class HmlRestController
{
#Autowired
private JmsTemplate jmsTemplate;
...
}
Raises the following exception:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'jms.destination.name' in value "${jms.destination.name}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
Here is my bootstrap.yml content:
spring:
application:
name: hml-core
profiles:
active:
default
cloud:
config:
uri: http://localhost:8888/hml
Going to http://localhost:8888/hml/hml-core/default correctly displays the properties. Did I miss anything ?

Depending on your logs, your client can't access to the Config Server, this is why the field jms.destination.name can't be injected.
Add the full stacktrace of your client will be helpful

Do you happen to have spring.main.sources set somewhere?
We had the excact same issue and removing that line helped us. It seems that having this in the bootstrap.yml hinders the app to connect to cloud config server. This results in missing props.
Also having spring.main.sources param on config server side caused a server side exception. See Spring cloud config /refresh crashes when spring.main.sources is set

I'm updating this post with the results of the last tests. It appears that including the maven dependencies in each of the modules solves the issue and the configuration is then found as expected.
In my original design I had a parent POM which factorized all the spring boot dependencies, as shown below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This way the configuration client doesn't find the config server and the mentioned exception is raised. Modifying the parent POM such that to include only the dependencyManagement, as shown below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
and moving the dependencies in the config server POM as follows:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
and in the config client as follows:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-rsa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
completely solves the problem and everything works as expected. I don't have any explanation of this as including all the common dependencies in the parent POM should have exactly the same effect as including them in each individual module. In my opinion this shows some instabilities and strange behavior of Spring Boot and Spring Cloud. I don't have time to dig more and to try to understand what happens. Anyway, given this kind of issues, as well as the lack of any support including on this site, we moved from Spring.
But if someone has any explanation of this, I'm still interested to know.
Kind regards,
Nicolas

Related

JPABUDDY tabs not appear in my intellij project

I've installed intellij CE with jpabuddy but jpa buddy not appears to be working in my current project.
This is my current pom.xml dependencies section
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jeasy</groupId>
<artifactId>easy-random-core</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
This is my current IDE right panel... as you can see JPA Palette is missing.
I'm running IntelliJ in a Kubuntu 22.04
After some research on this question https://stackoverflow.com/questions/71974527/jpa-buddy-missing-from-tool-window-in-intellij#:~:text=To%20see%20the%20JPA%20Buddy,is%20correct%20and%20reimport%20dependencies and some insights in the JPA BUDDY discord I've finally get the issue: It was running in minimalistic mode.
You can disable it following the documentation at its home page:
https://www.jpa-buddy.com/documentation/minimalistic-mode/#enabling-minimalistic-mode
I think you need the install the JPA Buddy plugin to see something in the right panel. Maven JPA dependencies are not enough.
Go to Preferences->Plugins and install JPA Buddy from the marketplace. Restart IntelliJ.

com.google.inject.ProvisionException: Unable to provision

I have created simple seedstack web project through guideline mentioned on http://seedstack.org/docs/basics/
Undertow is also started with seedstack:run.
However, while accessing "hello" resource undertow throws below exception:
ERROR 2018-07-25 21:37:34,468 XNIO-1 task-2 io.undertow.request
UT005023: Exception handling request to
/api/seed-w20/application/configuration
null returned by binding at
org.seedstack.w20.internal.W20Module.configure(W20Module.java:51) (via
modules: com.google.inject.util.Modules$OverrideModule ->
io.nuun.kernel.core.internal.injection.KernelGuiceModuleInternal ->
org.seedstack.w20.internal.W20Module) but the 3rd parameter of
org.seedstack.w20.internal.FragmentManagerImpl.(FragmentManagerImpl.java:32)
is not #Nullable at
org.seedstack.w20.internal.W20Module.configure(W20Module.java:51) (via
modules: com.google.inject.util.Modules$OverrideModule ->
io.nuun.kernel.core.internal.injection.KernelGuiceModuleInternal ->
org.seedstack.w20.internal.W20Module) while locating
org.seedstack.w20.internal.ConfiguredApplication
for the 3rd parameter of org.seedstack.w20.internal.FragmentManagerImpl.(FragmentManagerImpl.java:32)
while locating org.seedstack.w20.internal.FragmentManagerImpl while
locating org.seedstack.w20.FragmentManager
for field at org.seedstack.w20.internal.rest.application.ApplicationConfigurationResource.fragmentManager(ApplicationConfigurationResource.java:38)
while locating
org.seedstack.w20.internal.rest.application.ApplicationConfigurationResource
Any help please?
This is a bug introduced recently into the w20-bridge, which occurs when no w20.app.json configuration file is present.
You can workaround it by creating an empty-object w20.app.json file at the root of the classpath:
{}
You can also update the version of all w20-bridge dependencies to 3.2.4 which has a fix for it. This can be done by using the dependencyManagement section of your POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.seedstack</groupId>
<artifactId>seedstack-bom</artifactId>
<version>18.4.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web-bootstrap-3</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web-business-theme</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-web-components</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-rest</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.seedstack.addons.w20</groupId>
<artifactId>w20-bridge-specs</artifactId>
<version>3.2.4</version>
</dependency>
</dependencies>
</dependencyManagement>
This fix will be included in the upcoming SeedStack 18.7.

Latest ExtentReports maven dependency for selenium

I have added this in my POM file.
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.5</version>
</dependency>
It is not working for my project.
Try to change this strings in pom.xml:
<properties>
<selenium.version>3.0.5</selenium.version>
</properties>
<dependencies>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
</dependencies>
Your string <artifactId>extentreports</artifactId> probably should be writing earler in another block - it is not dependency, it is the Name of your Project.

What to add in settings.xml/pom.xml for apache archiva to work

** Apparently no one out there knows how to make this work. **
I have uploaded five jar files to apache archiva. The console is running and I can browse and see the, "pom snippet".
I have tried to add apache archiva information to my settings.xml:
<mirrors>
<mirror>
<id>Official1</id>
<url>http://repo1.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>apache archiva</id>
<url>http://172.##.##.##:8080</url>
<mirrorOf></mirrorOf>
</mirror>
And then added the snippet to my pom.xml file (last dependency in the list):
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>GroupFromApacheArchiva</groupId>
<artifactId>DatabaseDriver</artifactId>
<version>5.73</version>
</dependency>
</dependencies>
I then save everything and build but Maven can't resolve the newly added dependency.
What am I doing incorrectly?
When I pull out the apache archiva from the settings.xml and the GroupFromApacheArchiva from the pom.xml everything builds and runs normally.

MessageBodyWriter not found for media type=application/json even while Jackson is included

I've seen some solutions to this problem but it seems like following them doesn't solve my problem. I am returning a simple string array and when I return it, I am getting this error:
Severe: MessageBodyWriter not found for media type=application/json, type=class [Ljava.lang.String;, genericType=class [Ljava.lang.String;.
The method is really simple (gets a list of files)
#GET
#Produces(MediaType.APPLICATION_JSON)
public String[] getSegments(#PathParam("userId") String userId,
#PathParam("deviceId") String deviceId) {
System.out.println("in get, userId passed: " + userId);
String[] segments = storage.getSegments(userId, deviceId);
return segments;
}
My POM.XML seems to have all the things recommended in other posts:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>RoverServerLib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-servlet-portability</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache-connector</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${jersey.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>
The problem is with MOXy. It doesn't know how to handle String arrays. When you have MOXy on the classpath, it is the used as the default. To use Jackson (jersey-media-json-jackson). You just need to register the JacksonFeature. This will disable MOXy. Note that even just removing MOXy from your project, will have no affect, as Glassfish has it, so you need to make sure to register the JacksonFeature.
You should also get rid of jackson-jaxrs-json-provider. jersey-media-json-jackson already pulls it in (but a different version).
Another thing is that Glassfish already has it's own version of Jersey and friends. If you don't mark all your Jersey related dependencies as <scope>provided</scope>, then it's possible you may have version conflicts. So you should make them all provided. Glassfish 4.1 uses Jersey 2.10.4. If you need some newer version features, I would recommend updating Jersey in Glashfish.