Posts

Showing posts with the label Spring Boot

Call Another Rest Api From My Server In Spring-Boot

Answer : This website has some nice examples for using spring's RestTemplate. Here is a code example of how it can work to get a simple object: private static void getEmployees() { final String uri = "http://localhost:8080/springrestexample/employees.xml"; RestTemplate restTemplate = new RestTemplate(); String result = restTemplate.getForObject(uri, String.class); System.out.println(result); } Instead of String you are trying to get custom POJO object details as output by calling another API/URI , try the this solution. I hope it will be clear and helpful for how to use RestTemplate also, In Spring Boot , first we need to create Bean for RestTemplate under the @Configuration annotated class. You can even write a separate class and annotate with @Configuration like below. @Configuration public class RestTemplateConfig { @Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } } The...

@ConfigurationProperties Spring Boot Configuration Annotation Processor Not Found In Classpath

Answer : I had the same problem. I use idea 2017.2 and gradle 4.1, and some blog said you should add: dependencies { optional "org.springframework.boot:spring-boot-configuration-processor" } But I changed it to this: dependencies { compile "org.springframework.boot:spring-boot-configuration-processor" } And the warning is gone. According to the Spring Boot docs, the correct configuration since Gradle 4.6 is dependencies { annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor' // ... } IntelliJ IDEA supports annotationProcessor scope since build 193.3382 (2019.3). Don't forget to enable annotation processing in IntelliJ IDEA settings. It happens to me for two reasons in IDEA: Double check if your setting is picked (enabled) in IDEA: Preferences->Annotation Processors->Enable annotation processing. After update your Idea, check your plugins and update them. It happens that plugin...

Add Context Path To Spring Boot Application

Answer : Why are you trying to roll your own solution. Spring-boot already supports that. If you don't already have one, add an application.properties file to src\main\resources . In that properties file, add 2 properties: server.contextPath=/mainstay server.port=12378 UPDATE (Spring Boot 2.0) As of Spring Boot 2.0 (due to the support of both Spring MVC and Spring WebFlux) the contextPath has been changed to the following: server.servlet.contextPath=/mainstay You can then remove your configuration for the custom servlet container. If you need to do some post processing on the container you can add a EmbeddedServletContainerCustomizer implementation to your configuration (for instance to add the error pages). Basically the properties inside the application.properties serve as a default you can always override them by using another application.properties next to the artifact you deliver or by adding JVM parameters ( -Dserver.port=6666 ). See also The Reference...

Bootstrap.yml Configuration Not Processed Anymore With Spring Cloud 2020.0

Answer : As pointed put by Nicoll, With Spring Cloud Vault 3.0 and Spring Boot 2.4, the bootstrap context initialization ( bootstrap.yml , bootstrap.properties ) of property sources was deprecated . This can be fixed in one of the 2 ways Use Spring Boot 2.4.0 Config Data API to import configuration from Vault (Preferred) Legacy Processing: Enable the bootstrap context either by setting the configuration property spring.cloud.bootstrap.enabled=true or by including the dependency <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency> 1. Use Spring Boot 2.4.0 Config Data API (Preferred) Move bootstrap.yml configuration to application.yml and updated file looks like below application.yml spring: cloud: vault: authentication: APPROLE app-role: role-id: ${role-id} secret-id: ${secret-id} role: pres-read app-role...