I have a simple spring boot application on which I am trying to run a Eureka server.
This is my main application file.
#SpringBootApplication
#EnableEurekaServer
public class NetflixEurekaNamingServerApplication {
public static void main(String[] args) {
SpringApplication.run(NetflixEurekaNamingServerApplication.class, args);
}
}
This is my application property file
spring.application.name=netflix-eureka-naming-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
Dependencies used.
spring boot version : 2.2.4.RELEASE
spring cloud version : Hoxton.SR1
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
But when I run the application and visits the localhost:8761 then I get an Whitelabel page error showing 404 NOT FOUND.
and when I changed the configuration according to this post unable to render eureka dashboard
then it started showing me an XML page instead of the dashbord.
Can someone help me out here ?
Eureka Dashboard should be available unter http://localhost:8761/eureka/
I got the issue.
Just add these two properties in your application.properties file and it will work.
spring.freemarker.template-loader-path= classpath:/templates/
spring.freemarker.prefer-file-system-access= false
I am using spring boot version 2.2.4.RELEASE and springCloudVersion Hoxton.SR1
Related
I am using Quarkus inside a microservice Java application.
I recently started to migrate from Spring Boot to Quarkus itself.
I am having some trouble while migrating "Spring Cloud Consul" to "Quarkus Consul Config". In order to be more specific, I am getting the following error:
java.lang.RuntimeException: Key 'my/consul/path/application.yaml' not found in Consul
at io.quarkus.consul.config.runtime.ConsulConfigSourceProvider$1.accept(ConsulConfigSourceProvider.java:66)
at io.quarkus.consul.config.runtime.ConsulConfigSourceProvider$1.accept(ConsulConfigSourceProvider.java:56)
at io.smallrye.context.impl.wrappers.SlowContextualConsumer.accept(SlowContextualConsumer.java:21)
at io.smallrye.mutiny.operators.uni.UniOnItemConsume$UniOnItemComsumeProcessor.invokeEventHandler(UniOnItemConsume.java:77)
at io.smallrye.mutiny.operators.uni.UniOnItemConsume$UniOnItemComsumeProcessor.onItem(UniOnItemConsume.java:42)
at io.smallrye.mutiny.operators.uni.UniOnItemTransform$UniOnItemTransformProcessor.onItem(UniOnItemTransform.java:43)
at io.smallrye.mutiny.vertx.AsyncResultUni.lambda$subscribe$1(AsyncResultUni.java:35)
(...)
Inside my Consul instance, the key my/consul/path/application.yaml corresponds to an application.yaml external file that I would like to import from there during the startup phase.
Below you can find my consul config (application.yaml):
quarkus:
application:
name: myapplication
consul-config:
enabled: true
properties-value-keys: my/consul/path/application.yaml
agent:
host-port: http://localhost:9500
prefix: myappprefix
If I try to switch from properties-value-keys to properties-raw-value-keys, I see that my property is not being injected inside my application context:
#ConfigProperty(name = "consultest")
String test;
java.util.NoSuchElementException: SRCFG00014: The config property consultest is required but it could not be found in any config source
Below you can find the application.yaml content (located on Consul):
consultest: testtest
The intent, here, is to delegate application.yaml properties to Consul, divided by environment (dev, test, prod).
I would like to threat my local application.yaml file (located in src/main/resources) as a bootstrap.yaml file, similarly to Spring Boot approach.
How could this be done with Quarkus? Thank you a lot for your support.
I have added pom dependency in the spring boot application for graphiql playground with the "graphiql-spring-boot-starter-5.0.2.jar" dependency.
Now I would like to disable the playground for the production environment.
And have tried with spring boot applications as below, but none of these options working to disable the GraphiQL endpoint.
graphiql.enabled= false
dgs.graphql.graphiql.enabled=false
Could you please suggest how we could disable GraphiQL?
You can actually add the below configuration in your production profile inside application.yml or application.properties to disable the playground in the production.
I have tested it with com.graphql-java:playground-spring-boot-started:11.0.0
In application.yml
graphql:
playground:
enabled: false
In application.properties
graphql.playground.enabled = false
When running
./mvnw spring-boot:run
current spring boot application can open in the browser with current URL
http://localhost:8080/
but not
http://localhost:8080/AppName
So even in Swagger the APIs has to retrieve like this
http://localhost:8080/api/swagger.json
instead of this
http://localhost:8080/AppName/api/swagger.json
So how to add the AppName in the context? Easy in the old days where web.xml is xml based, in java based config I have add
spring.application.name=AppName
but still don't resolve the issue.
So how to add the AppName in the context?
Spring Boot, by default, serves content on the root context path (“/”), But we can change it in different ways.
1) Using application.properties / yml
For Boot 1.x, the property is server.context-path=/AppName
For Boot 2.x, the property is server.servlet.context-path=/AppName
2) Using Java system property
public static void main(String[] args) {
System.setProperty("server.servlet.context-path", "/AppName");
SpringApplication.run(Application.class, args);
}
3) Using OS Environment Variable
On Linux:- $ export SERVER_SERVLET_CONTEXT_PATH=/AppName
On Windows:- set SERVER_SERVLET_CONTEXT_PATH=/AppName
4) Using Command Line Arguments
$ java -jar app.jar --server.servlet.context-path=/AppName
5) Using Java Config
With Spring Boot 2, we can use WebServerFactoryCustomizer:
#Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>
webServerFactoryCustomizer() {
return factory -> factory.setContextPath("/AppName");
}
With Spring Boot 1, we can create an instance of EmbeddedServletContainerCustomizer:
#Bean
public EmbeddedServletContainerCustomizer
embeddedServletContainerCustomizer() {
return container -> container.setContextPath("/AppName");
}
Note:- Priority order in descending order, which Spring Boot uses to select the effective configuration:
Java Config
Command Line Arguments
Java System Properties
OS Environment Variables
application.properties in Current Directory
application.properties in the classpath (src/main/resources or the packaged jar file)
Set the context path
Spring Boot 1.x: server.contextPath=/AppName
Spring Boot 2.x: server.servlet.contextPath=/AppName
You should use
server.servlet.context-path for Spring Boot 2.x
server.context-path for Spring 1.x
in your application.properties file.
Add the following line in your application.properties (works with Spring Boot 1.x):
server.contextPath=/AppName
if your version is 2.x, the use the following:
server.servlet.contextPath=/AppName
I have one spring boot jar packaging helloworld soap web service and it works as jar project. But I need war file, i convert it to war packaging project and then deploy to tomcat, but when i test with soapui request return error. This is my test project link:
https://drive.google.com/open?id=1ChKcOxeOGkFpGpjYUh3FabdUFFueRWCw
I want ask, if someone have spring boot soap web service that works correctly?
i use eclipse maven project, tomcat 8.5.23 and soapui, jdk 1.8
this is some part of error text
:
HTTP Status 404 – Not Found HTTP Status 404 – Not Found /codenotfound/ws/helloworldDescription The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.Apache Tomcat/8.5.23
Add "SpringBootServletInitializer" as shown in following code to your main file. Because without SpringBootServletInitializer Tomcat will consider it as normal application it will not consider as Spring boot application
#SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication .class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication .class, args);
}
}
I have the following spring-boot 1.4.2.RELEASE sample app
#SpringBootApplication
public class Application {
#Value("${spring.application.name}")
private String applicationName;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
And I have the following configuration defined in bootstrap.properties:
spring.application.name=sample-app
When run it I get the following error:
java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.application.name' in string value "${spring.application.name}"
Any hint on why it fails to inject 'spring.application.name'?
Need to define it there to support other spring boot cloud.
The first answer is correct. The default properties file is application.properties or application.yml.
The bootstrap file is properly for Spring Cloud.
See http://projects.spring.io/spring-cloud/spring-cloud.html#_the_bootstrap_application_context
If you are using spring cloud, and the bootstrap file is not working, you need to enable the "cloud" Spring profile.
For example using:
./gradlew -Dspring.profiles.active=cloud bootrun
or
./mvnw spring-boot:run -Dspring.profiles.active=cloud
By default, if you don't specify any properties source, spring boot will lookup for your property in the file application.properties. Therefore, you should rename your property file to that default name or manually specify a properties source for your bootstrap.properties