Using the spring-boot-actuator, I can access my project's current build version when I enter the uri myApp:8080/.../env. Env is a spring actuator endpoint.
This uri, returns, among other data, my current build version -- info.build.version_component":"1.0.101".
I want to have access to the build version in my code for logging purposes. Is there a way I can access this data coming from the env endpoint and print it in my code?
Related
Enviroment :k8s
Issue : I change ip,port,username,password database in application.properties file, I must build my application again to update new information.
Expect :
When I change database information(Example: ip,port) in application.properties, I want my quarkus application will not build again.
I am trying to run a spark job on a Hadoop cluster that also makes an http request to another server. I am using org.apache.httpcomponents to make this request, which works fine locally on my machine. However this fails the moment I submit the job to the cluster (managed by Cloudera) with the following error:
User class threw exception: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:151)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977)
at org.apache.http.impl.client.HttpClients.createDefault(HttpClients.java:56)
From all the reading I have done, this error is caused by multiple versions of Apache Http client jar. It appears that Hadoop/Spark engine has it's own dependency to Apache Http client and that is a different version than the one I am using. Because my jar is run as part of the hadoop/spark engine it ends up including both my version of http as well as the one Hadoop requires.
If I add 'compileOnly' for org.apache.httpcomponents in my build.gradle and submit, I get this error instead:
User class threw exception: java.lang.NoClassDefFoundError: org/apache/http/impl/client/HttpClients
Is there a way for me to configure this in gradle so that when I build my jar, it will use the already existing version on Hadoop? ie. A way to declare a temporary dependency (when running locally download and use latest version, but when building UberJar drop the dependency)?
UPDATE
I decided to try swapping to a different http library (okhttp3) to see if that would resolve the issue. However I get a very similar exception when trying to run through the cluster here too:
User class threw exception: java.lang.NoSuchFieldError: Companion
at okhttp3.internal.Util.(Util.kt:70)
at okhttp3.OkHttpClient.(OkHttpClient.kt:959)
Looks like Cloudera also supplies a version of okhttp with it's spark2 client which is unfortunate.
I am using JMeter version 5.0 r and I am following [this tutorial]
(https://docs.wso2.com/display/EI630/Point-to-Point+Messaging#865c10b8d4d64ac688d6a0799cfb6012),
jndiqueues.properties
# register some connection factories
# connectionfactory.[jndiname] = [ConnectionURL]
connectionfactory.QueueConnectionFactory = amqp://admin:admin#clientID/carbon?brokerlist='tcp://localhost:5675'
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.FirstQueue = myfirstqueue
when I am running this JMS publisher I am getting error as:
Response message: javax.naming.NamingException: javax.naming.NoInitialContextException: Cannot instantiate class: org.wso2.andes.jndi.PropertiesFileInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.wso2.andes.jndi.PropertiesFileInitialContextFactory ]
This jar is already there in lib folder still I added want to add it in classpath because it was giving this error. So I edited user.properties file, like mentioned in an answer here:
user.classpath=../classes;../lib;../app1/jar1.jar;../app2/jar2.jar;../lib/andes-client-4.0.0.jar
But still I am getting same error. What am I doing wrong?
If you copied andes-client-4.0.0.jar to "lib" folder of your JMeter installation there is no need to set up user.classpath property, JMeter will automatically pick it up.
Remember that you need to restart JMeter for any property change application and when you add .jars under JMeter Classpath, otherwise the changes will not be picked up.
More information:
JMeter Properties Reference
Apache JMeter Properties Customization Guide
You can also add the libraries to JMeter Classpath at Test Plan level like:
in that case JMeter restart will not be required
try the same you did but using absolute class paths instead of relative ones
What it worked for me was to use:
<propertiesJMeter>
<search_paths>${project.basedir}/some_path</search_paths>
<user.classpath>${project.basedir}/some_path</user.classpath>
</propertiesJMeter>
Hope it helps
I am attempting to use the google vision library in java. The steps specify that I need to setup my auth credentials in order to start using the this library . I was able to generate my json property file from API Console Credentials page and I placed it in my spring boot app in the resources folder.
I think updated my application.properties file to include the value like so:
GOOGLE_APPLICATION_CREDENTIALS=datg-avatar-generator-9dc9155cd5bd.json
I'm also setting my property source in my controller like so:
#PropertySource("${GOOGLE_APPLICATION_CREDENTIALS}")
However, after doing that I'm still getting an error saying:
java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
I was able to configure this property using Spring Cloud GCP spring-cloud-gcp-starter-data-datastore, creating a service account project owner, copy the JSON private key to the main resources directory, and setting the following properties in the application.properties
spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=classpath:<credentials-private-key>.json
from the documentation
You can find the project id by visiting this page https://support.google.com/googleapi/answer/7014113?hl=en
Go to the API Console.
From the projects list, select Manage all projects. The names and IDs for all the projects you're a member of are displayed.
You can also select the project go the settings and see the project ID
You can use application properties, but you need to use a different StorageOptions builder.
You are probably using
private static Storage storage = StorageOptions.getDefaultInstance().getService();
But if you want to skip the environment variable you need to use:
Credentials credentials = GoogleCredentials
.fromStream(new FileInputStream("path/to/file"));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials)
.setProjectId("my-project-id").build().getService();
Note that the default builder (using environment variables) is better if you are going to deploy your applications to cloud, because then this is automatically filled for you.
You need to set the shell variable. Run this command before mvn run.
export GOOGLE_APPLICATION_CREDENTIALS="/Users/ronnyshibley/Dev/eddress-service-key.json"
For authentication using the service account key, you can set the Environment Variable in your shell.
export GOOGLE_APPLICATION_CREDENTIALS="/Users/username/directory/service-key-file-name.json"
Then you need to start your IDE from the same session. I was stuck after exporting and setting up the environment variable and was still unable to use it.
I tried quitting the current IDE window and restarted the IDE again from the same session.
In my case it was Intellij, so in the terminal itself,
cd project directory
idea .
Or you can also add the environment variable in your bash profile and then source it.
I have tried several ways to do this, and none of them worked. Maven plugin
environmentVariables is the last thing that worked without any problem.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<executable>true</executable>
<environmentVariables>
<GOOGLE_APPLICATION_CREDENTIALS>/path/to/the/service-account.json</GOOGLE_APPLICATION_CREDENTIALS>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
You need to add env variable
GOOGLE_APPLICATION_CREDENTIALS=<path to google project json file >
If you are using IntelliJ idea, Edit the Project configuration and add the Environment variable
For images check this
https://www.twilio.com/blog/set-up-env-variables-intellij-idea-java
I'm novice to use spring cloud config server, so is first time for me and i hope i can receive help, thanks in advance for this.
What i can try to do is to configure Spring cloud Configuration Server as central server for configurations among all Microservices.
We are using AWS CodeCommit as SCM repository.
The problem is that i receive always the same error once i try to inve an existing file on AWS CC.
I suppose is a problem of authentication, but i'm not sure
Error screenshot
This is the bootstrap configuration on Spring CSC
server.port=9090
management.security.enabled=false
logging.level.org.springframework.web: TRACE
spring.application.name=config-service
spring.cloud.config.server.git.uri: https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/ServiceLayer
This is the file in my SCM repository that i'm trying to call:
configuration:
projectName: ms-login
server:
port: 8000
message:
greeting: Hello from the configuration
I've make a several try:
Placed the AWS GIT Credential (NOT the AWS Secret key) in bootstrap properties, but without result. Example:
spring.cloud.config.server.git.username: sergio.greco-at-682088819034
spring.cloud.config.server.git.password: xxxxxxx
Placed the AWS Secret Key \ Identity ID as java parameter once start, as follow:
-Daws.accessKeyId=xxxxxxxxYNOA -Daws.secretKey=xxxxxxxxxxxxxxxx
Set environment variables AWS_ACCESS_KEY_ID \ AWS_SECRET_ACCESS_KEY.
Can someone help me?
You need has the AWS SDK in the classpath.
Relevant documentation on this: http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.3.1.RELEASE/
Search for “Authentication with AWS CodeCommit”.
Note: The aws-java-sdk-core jar is an optional dependency. If the aws-java-sdk-core jar is not on your classpath, then the AWS Code Commit credential provider will not be created regardless of the git server URI.