I know that this is a very trivial question but please suggest me to find the way. Sometimes when I start Spring Boot server, it stops but it does not display the complete error/exception stack trace. Think of situation that spring boot server has been started in 8080 port and if somebody starts in 8080 port, it should clearly display that java.net.BindException. But in my case server simply aborts.
I normally find the issue from the IDE like eclipse/Idea when I start the server in debug mode. But how to find the error when somebody starts spring boot server using command prompt ? There may be many errors for which spring boot is unable to start. My question is what configurations should be added in application.properties to know more details about the error/s for which spring boot is not getting started. Currently I am using Spring Boot 2.1.1.RELEASE version. Please help me fix this.
To see more details of the actions being carried out for a spring boot application, change the log level to debug. You can do it just by simply adding below lines in application.property/yaml file.
logging.level.=DEBUG
Or for web applications you can try
logging.level.org.springframework.web: DEBUG
Add the below property in application.xml - worked in Spring boot 2.2.4
logging.level.root:ERROR
Related
I am trying to connect to a consul server from a Spring boot application, which fails because spring cloud consul doesn't seem to read my host configuration.
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to
localhost:8500 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]
failed: Connection refused: connect
The documentation says that we need to set the consul host from the bootstrap.properties/yml file. I have tried setting spring.cloud.consul.host in using by yml and properties format:
spring.cloud.consul.host=myhost (with the appropriate format for .properties vs. .yml)
or
spring.cloud.consul.host=myhost - fun fact, this works correctly when passing in as a program argument.
Dependencies:
spring-boot-starter-parent - 2.0.4.RELEASE
spring-cloud-starter-consul-all - 1.3.2.RELEASE
Cloud consul starter 1.3.x is not compatible with spring boot 2.x so it may be issue. Try with spring boot 1.5.x version instead.
Works for me with both Finchley (2.0.x) and Greenwich cloud version (2.1.x) and spring boot 2.0.x. More here. Compatibility matrix can be found at the bottom of page.
It sounds like your bootstrap.yml file is not getting loaded. Do you have the spring-cloud starter as a dependency (pom.xml if using Maven to build)? If it's included then the issue is probably to do with how you are starting the app. Are you running from the command line, or using Intellij/Eclipe to run it? There is probably something about the runtime environment that is causing the bootstrap.yml to not get loaded.
Please provide more details around how you are starting this app if you are still having issues with this.
do not judge this question) I want to implement WEB installer for my Spring Boot application, and very interesting moment is that my application plays 2 role: Installer and Backend(Application). When i first run my app i need to tell Spring to not initialize particular beans(Hibernate(while startup application must not to be failed to start because database may not exist), ActiveMq and others beans that will be added in installation process) and show some html pages with installation guide. Also i need to prevent access to endpoints where some logic with database occurs. When installation finished i will create new application.properties or some other file with settings and i tell Spring to initialize all required beans with Hibernate, ActiveMQ and others. Maybe i will make restart of application and new behaviour that based on installation will occur. And in next starts my application will not show installation guide. To simplify the question: I need to change startup behaviour of Spring Boot Application. For fun i can give an example with human: I need to make human live with no organs, and this human will live very good, and if i want i can add organs to human and he will be live very well))
You can use #Profile annotation. Check this link: https://www.mkyong.com/spring/spring-profiles-example/
I am using spring boot application with hibernate to connect to postgressql, but when I am running my application with run as spring boot app the starting of server is stuck with loading hibernate files
without any error, I am stuck on this and it's not also showing any error.
Does anyone have any idea?
Add the following to your app properties
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
or in your code the below
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
Hope it helps!
There was another instance of Postgresql server was running and i was also not able to kiss the process that's why the application was stuck, i restarted my system and its working fine
If you are using JPA, check your repository configuration. Spring can spend a very long time scanning for JPA repositories if you don't have basePackages or basePackageClasses set in your #EnableJpaRepositories annotation (this can be added by JpaRepositoriesAutoConfiguration if your setup meets that class's #ConditionalOn requirements).
I've been trying to figure out what I'm missing with my RestTemplate setup (particularly OAuth2RestTemplate) so I want to see the logs for debugging. I found one possible solution for it, but nothing about the operation of the RestTemplate gets shown.
What I've done so far is to replace the default Logback logging mechanism in my Spring Boot app by following the configuration shown here. When I run my Spring Boot application after changing the logging dependencies, all I see on the console is the Spring logo (in ASCII) and nothing else. I've already defined a log4j-spring.properties in src/main/resources with the property defined in the previous link.
What else am I missing here? Do I need to run my Spring Boot app in debug mode? If so, how do I do that? Also, how do I set this up using the default Logback mechanism?
I'm new to spring MVC 4 and I have a problem- Each time I start a new project there is something wrong with the configuration which results in a 404 when I try to work with my controllers.
I there a way to see some logs which will make things more clear as to what I did wrong? I work with tomcat and I looked into his "logs" folder and there was nothing there...
I suggest you to use remote debugging from your Eclipse IDE, or debug the application from within the IDE. then you can debug the code line by line and see what is going wrong.
For Spring application development Spring Tool Suit has more support for developing Spring Applications.
EDIT:
You can also configure your Log level in Tomcat Environment. See this article for more information to change your configuration of logging accordingly (Run on DEBUG mode)