spring contract cloud AutoConfigureStubRunner - spring-boot

In my spring cloud contract test I have already some remote stubs like after I followed the spring cloud contract docs https://cloud.spring.io/spring-cloud-contract/2.0.x/multi/multi__spring_cloud_contract_stub_runner.html
#AutoConfigureStubRunner(repositoryRoot = StubRunnerRepositoryRoot.URL, stubsMode =
StubsMode.REMOTE, ids = {
"uk.co.blah.service:blah-service:+:stubs"...})
However, I would also like to have some local stubs
stubsMode = StubsMode.LOCAL
So basically having some remote stubs and some local ones? Is that possible? Having multiple AutoConfigureStubRunner? It doesn't seem to work?
Thanks

If you want to do local only, you need to ensure that you have them in your local m2. It will be enough for you to add that stubs JAR as a dependency in your project and it will be downloaded to your local .m2 upon building of the project. Then you can use LOCAL and it will work cause you have just downloaded the jar.

Related

Spring Cloud Config Server Separate Repository

I am using Spring Cloud Config Server first time and have a basic query.
Spring Config server externalises the configuration to a separate git repository.
Why would I create a separate repository just for the configurations?
Is not it advisable to have mono repository with all application code and configurations in a single repo than creating a separate one just for configurations.
We have multiple micro services all present in the same repository. Should not the config server to be one of the micro service present in the same repository where the other application code is?
So, in my multi-module gradle project, I can make config-server as one of the module and give the same repository name as git backed url in config-server. Is this advisable? If yes, where should I keep the configurations in config-server? Inside resources?
Thank you.
When working with microservices it is advisible to have one repository for each microservice. The config server is a microservice as well, therefore it should be put in a separate repository.
Each microservice should have its own independent code repository and your application configuration should never be in the same repository as your source code.
You can read more about this here: Heroku's The Twelve-Factor App. Here you can find 12 best practices to use when building microservices, but for this question I recommend looking at
1st factor: The codebase
3rd factor: The config

Secure some keys in application.properties - spring boot application

I have a spring boot application where I am using some aws services.
The code in openly available in Git.
I don't want to commit AWS secret and access keys which are part of application.properties. I can't add to .gitignore as I want to commit other values of application.properties.
Many are committing to this repo. We are adding these aws keys in local and making sure its not added as part of any commit.
I want to make sure the aws keys in application.properties should not come to git at any cost. Which is the best way to manage these secret keys.?
You shouldn't be placing AWS API keys in application.properties at all. If the application is running on AWS it should be using the IAM role of the server it is running on. If it is not running on AWS it should probably be using environment variables.
Please review the documentation on this subject here.
Thanks to #Mark B. I would prefer using Java system properties as we can maintain them at application level. Env variables will be at system level which is not really needed and it may lead to conflicts.
while running an spring-boot jar with mvn, it can be done as below
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Daws.accessKeyId=XXXXXXXXXXX -Daws.secretKey=XXXXXXXXXXX"
if running for IDE like Eclipse or IntelliJ, it should be added as VM Options.
-Daws.accessKeyId=XXXXXXXXXXX -Daws.secretKey=XXXXXXXXXXXX
After this AWS client object can be built as usual.
As an example,
SNS client can be build by
AmazonSNS snsClient = AmazonSNSClient.builder().withRegion(Regions.US_EAST_1).build();
SES client can be built by
AmazonSimpleEmailService emailClient = AmazonSimpleEmailServiceClientBuilder.standard().withRegion(Regions.US_EAST_1).build();

How to Register Local Spring cloud task project jar file to spring cloud data flow dashboard

I am trying to register my local spring cloud task jar file into spring cloud task data flow graphical interface. While registering the application local path is not getting identified and Register button is not getting enabled. My jar file location is C:\STS-WORK_SPACE\SPRING-BATCH\SCDFBatch\target\SCDFBatch-0.0.1-SNAPSHOT.jar and path I provided in the Dashboard is file:///C:/STS-WORK_SPACE/SPRING-BATCH/SCDFBatch/target/SCDFBatch-0.0.1-SNAPSHOT.jar. Please correct me if I am wrong here. I need someones help here.
Please have a look at the spring data flow documentation related to your question.
docs.spring.io/spring-cloud-dataflow/docs/current/reference/html/getting-started-deploying-spring-cloud-dataflow.html#getting-started-maven-configuration
As per the spring documentation, the maven localRepository is set to ${user.home}/.m2/repository/ by default.
Hence dont specify complete path of your artifact in the dashboard, rather specify maven resource details in the following format maven://group:artifact:version. Then spring dataflow server automatically picks it from your local maven repo.
This question is a bit old, but here's how you can do that with SCDF 2.4.0:
Get the docker-compose from here: https://dataflow.spring.io/docs/installation/local/docker/
Customize it to mount your local .m2 folder, as described here: https://dataflow.spring.io/docs/installation/local/docker-customize/ in the section Maven Local Repository Mounting
Start Docker Compose
Then when SCDF is up, you need to register your artifact, e.g.
If you have a Maven project, do a mvn clean install for it, and in your .m2 folder you should have the artifacts (jar and pom). So verify that it's there first, before registering it.

Artifactory maven-metadata.xml and bundles with Java API

I'm attempting to upload & deploy a jar that we receive from a vendor into Artifactory using the Java API (artifactory-java-client-services v1.1.0). My uploads don't generate maven-metadata.xml and I can't find an option to auto-generate a pom.xml. I also can't find how I would indicate that I'm uploading a bundle rather than a single file.
Currently I'm using a simple snippet of code to upload a test jar and a simple pom:
Path jarPath = Paths.get(tmpDir.toString(), "test1.jar");
RepositoryHandle repositoryHandle =
ArtifactoryClient.create(url, username, password).repository(repositoryName);
UploadableArtifact jarArtifact =
repositoryHandle.upload("com/company/play/1.0.0/test.jar", jarPath.toFile());
File responseFile = jarArtifact.upload();
I use the same process to upload the pom.xml.
So:
Is there a way to request the maven-metadata.xml be recalculated as in the REST call shown here?
Is there any way to indicate that Artifactory needs to auto-generate a simple pom.xml on upload with the Java API?
Is there any way to indicate that the upload is a bundle?
Thanks in advance!
maven-metadata.xml is generated automatically upon deployment. Note that it might take some time – indexing and metadata generation is an async task.
pom.xml generation is not triggered from REST API or Java API ATM. Didn't you mention that you upload the pom.xml?
Not sure what you mean by "bundle". OSGi bundle? Or an archive that you expect Artifactory to unzip and deploy? In case of OSGi bundle there is nothing needed to be done, in case of the archive, again, it's not supported ATM.

How to combine 3 standalone applications on java and run parallely with maven in spring

How to combine 3 standalone applications on java and run parallely with maven in spring.
The three othe standalone applications run on different Db's and I want to make use of these three in my main Standalone app.
What are the required maven settings i need to follow and what are the best spring components i used.
Any kind of answer is appresiable.
Thanks in Advance.
About Maven.
I recomend you to use a Repository Manager (Nexus, Artifactory...). In that repository, you can upload manually your aplications as a jar (I assumed that these three app are not build with Maven, but it could be interesant to migrate them, you should evaluate that).
You have to configure your new app pom.xml and settings.xml to get access to this repository. And then, you can add these dependencies in your new app pom.xml. After that, you can use your applications classes in your new app.
About Spring
Spring Framework, has a lot of things that could help you in your development (like dependency injection, jdbcTemplate and a large etc)
I really recommend you to read the documentation (with the index you can get an idea), and evaluate what things could help you.

Resources