spring application does not use embedded tomcat - spring

The spring application won't run as web application and does not use the embedded tomcat server. I have provided my console and pom.xml logs. Please help me.
2017-03-17 01:38:09.426 INFO 18696 --- [ main] io.springbootstarter.SpringCourseApi : Starting SpringCourseApi on gandy with PID 18696 (C:\Spring\workspace\course-api\target\classes started by gandhar in C:\Spring\workspace\course-api)
2017-03-17 01:38:09.431 INFO 18696 --- [ main] io.springbootstarter.SpringCourseApi : No active profile set, falling back to default profiles: default
2017-03-17 01:38:09.539 INFO 18696 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#5ae50ce6: startup date [Fri Mar 17 01:38:09 MDT 2017]; root of context hierarchy
2017-03-17 01:38:11.361 INFO 18696 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-03-17 01:38:11.383 INFO 18696 --- [ main] io.springbootstarter.SpringCourseApi : Started SpringCourseApi in 2.662 seconds (JVM running for 3.22)
2017-03-17 01:38:11.384 INFO 18696 --- [ Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#5ae50ce6: startup date [Fri Mar 17 01:38:09 MDT 2017]; root of context hierarchy
2017-03-17 01:38:11.385 INFO 18696 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
This is my console output when i try to run a web application. My pom.xml looks like this -
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springboot.courses</groupId>
<artifactId>course-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Course_API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
</project>

Related

This site can’t be reached localhost refused to connect. on empty project

My localhost does not load the page:
http://localhost:8080/
This site can’t be reached
localhost refused to connect.
I have a brand new project and when I run the project I don't get any errors or see any errors but when I try to view using the localhost I see the above error
Here is the detail on my project.
Java version on my machine:
C:\WINDOWS\system32>java -version java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
I have no idea what I'm doing wrong here, and again I have nothing except this class which I run:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
My POM file:
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.4.2
com.example
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Application log:
2021-01-16 19:24:07.268 INFO 23308 --- [ main]
com.example.demo.DemoApplication : Starting DemoApplication
using Java 13.0.2 on XPS8910 with PID 23308
(C:\Users\nick\eclipse-workspace\demo\target\classes started by
XPS89100 in C:\Users\nick\eclipse-workspace\demo) 2021-01-16
19:24:07.270 INFO 23308 --- [ main]
com.example.demo.DemoApplication : No active profile set,
falling back to default profiles: default 2021-01-16 19:24:07.740
INFO 23308 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
JPA repositories in DEFAULT mode. 2021-01-16 19:24:07.752 INFO 23308
--- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 4 ms. Found 0 JPA
repository interfaces. 2021-01-16 19:24:08.143 INFO 23308 --- [
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized
with port(s): 8080 (http) 2021-01-16 19:24:08.151 INFO 23308 --- [
main] o.apache.catalina.core.StandardService : Starting service
[Tomcat] 2021-01-16 19:24:08.151 INFO 23308 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine:
[Apache Tomcat/9.0.41] 2021-01-16 19:24:08.274 INFO 23308 --- [
main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring
embedded WebApplicationContext 2021-01-16 19:24:08.274 INFO 23308 ---
[ main] w.s.c.ServletWebServerApplicationContext : Root
WebApplicationContext: initialization completed in 961 ms 2021-01-16
19:24:08.429 INFO 23308 --- [ main]
o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing
PersistenceUnitInfo [name: default] 2021-01-16 19:24:08.473 INFO
23308 --- [ main] org.hibernate.Version :
HHH000412: Hibernate ORM core version 5.4.27.Final 2021-01-16
19:24:08.586 INFO 23308 --- [ main]
o.hibernate.annotations.common.Version : HCANN000001: Hibernate
Commons Annotations {5.1.2.Final} 2021-01-16 19:24:08.670 INFO 23308
--- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
It looks like spring application didn't start completely and freezes on starting Hikari Pool (last line in your log).
Hikari pool is a database connection pool. This probably means that the DB connection settings in your application.properties are incorrect and connection can't be established.
Can you verify that database is running and responding on the datasource URL you configured?

Spring Boot and Liquibase: migrations not being executed when initiating the server

My microservice for running migrations with Liquibase and MongoDB doesn't execute the migration when the server starts up, as claimed to do with Spring Boot.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-mongodb</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
spring:
application:
name: photo-app-liquibase
datasource:
driver-class-name: liquibase.ext.mongodb.database.MongoClientDriver
url: mongodb://localhost:27017/photo-app
liquibase:
change-log: classpath:db/changelog/db.changelog-master.xml
The migration and master file are located in src/main/resources/db/changelog folder
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<!-- Tried without "db/changelog" and appending "./" before already -->
<include file="db/changelog/20201029215628_create-users-table.xml"/>
</databaseChangeLog>
But when starting up the server, no sign of the migration being run and also nothing changes in the database.
2020-10-30 08:32:04.928 INFO 12065 --- [ main] c.g.p.PhotoAppLiquibaseApplication : Starting PhotoAppLiquibaseApplication on gabriel with PID 12065 (/home/gabriel/Workspace/spring/spring-microservices-ii/photo-app-liquibase/target/classes started by gabriel in /home/gabriel/Workspace/spring/spring-microservices-ii/photo-app-discovery-service)
2020-10-30 08:32:04.933 INFO 12065 --- [ main] c.g.p.PhotoAppLiquibaseApplication : No active profile set, falling back to default profiles: default
2020-10-30 08:32:05.559 INFO 12065 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2020-10-30 08:32:05.582 INFO 12065 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 MongoDB repository interfaces.
2020-10-30 08:32:05.864 INFO 12065 --- [ main] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2020-10-30 08:32:05.920 INFO 12065 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:22}] to localhost:27017
2020-10-30 08:32:05.928 INFO 12065 --- [localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=4278944}
2020-10-30 08:32:06.134 INFO 12065 --- [ main] c.g.p.PhotoAppLiquibaseApplication : Started PhotoAppLiquibaseApplication in 1.729 seconds (JVM running for 2.57)
Process finished with exit code 0
Liquibase doesn't support MongoDB, but they provide an extension to support MongoDB:
=> How to use Liquibase-MongoDb-Spring-boot

Empty list of Keys refreshed [] on Spring Cloud Config Server (Spring Boot application)

In my Spring Cloud config server pom.xml I have
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M8</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
In bootstrap.properties I have specified with spring.cloud.config.server.git.uri the repository to fetch configuration properties from (as yml files). I have set up a Github webhook and have ngrok forwarding POST requests to port 8888 that the config server is listening on. When I commit a change to a yml configuration file, everything seems to go as expected:
In ngrok console window there is a POST request to /monitor and response with 200.
The delivery is marked successful on Github's webhook management page.
The following log entries are created in config server's console window.
2018-03-14 13:55:03.023 INFO 17004 --- [nio-8888-exec-3] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: develop_localhost
2018-03-14 13:55:04.451 INFO 17004 --- [nio-8888-exec-3] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2018-03-14 13:55:04.483 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1: startup date [Wed Mar 14 13:55:04 EET 2018]; root of context hierarchy
2018-03-14 13:55:04.521 INFO 17004 --- [nio-8888-exec-3] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$5a4e4f18] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-03-14 13:55:06.027 INFO 17004 --- [nio-8888-exec-3] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2018-03-14 13:55:06.041 INFO 17004 --- [nio-8888-exec-3] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2018-03-14 13:55:06.043 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#429eafc3: startup date [Wed Mar 14 13:55:06 EET 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1
2018-03-14 13:55:06.053 INFO 17004 --- [nio-8888-exec-3] o.s.boot.SpringApplication : Started application in 3.024 seconds (JVM running for 97.323)
2018-03-14 13:55:06.054 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#429eafc3: startup date [Wed Mar 14 13:55:06 EET 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1
2018-03-14 13:55:06.055 INFO 17004 --- [nio-8888-exec-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#d3f5ec1: startup date [Wed Mar 14 13:55:04 EET 2018]; root of context hierarchy
2018-03-14 13:55:06.128 INFO 17004 --- [nio-8888-exec-3] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
Why is the list of keys refreshed empty? When I check the local property source yml file, the change committed on Github and POSTed to the monitor endpoint is not reflected there either. I am running RabbitMQ on another server in my local network, and I can see on its web management console the connection from the config server and the channel created for it. Yet there are no messages on the overview tab.
This used to work with Spring Boot 1.5.4.RELEASE and Spring Cloud Dalston.SR5 on the occasions when the embedded Tomcat/Jetty managed to start. The main reason to try version upgrades was that the servlet container actually started only like in 10% percent of the launches. Now with Spring Boot 2.0.0.RELEASE and Spring Cloud Finchley.M8, Tomcat always starts but the configuration changes do not seem to propagate to the config server and definitely not to RabbitMQ.
Any ideas?
Edit June 5th, 2018.
Now that I have updated spring-boot-starter-parent to 2.0.2.RELEASE in the config server pom.xml, config client gets its configuration from it. But as before, no push notification is propagated to RabbitMQ. Both the config server and client have their respective connections, channels and queues with RabbitMQ.
Now if I change spring-cloud.version to Finchley.BUILD-SNAPSHOT or Finchley.RC2 (and keep Spring Boot 2.0.2.RELEASE or change it to 2.0.1.RELEASE, no difference), I can see a queued message from the config server on the RabbitMQ web management console when it receives a push notification. Fine. The downside of the combination is that when config client tries to fetch its settings from the server, the server logs the exception below
2018-06-04 16:16:12.352 ERROR 10428 --- [nio-8888-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot load environment] with root cause
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source) ~[na:1.8.0_144]
at org.springframework.cloud.config.server.environment.HttpClientConfigurableHttpConnectionFactory.lookupHttpClientBuilder(HttpClientConfigurableHttpConnectionFactory.java:69) ~[spring-cloud-config-server-2.0.0.BUILD-SNAPSHOT.jar!/:2.0.0.BUILD-SNAPSHOT]
and because the client does not get its configuration, it fails to boot.
What would be the working combination of Spring Boot and Cloud versions to have both full RabbitMQ integration (with messages propagated to RabbitMQ) and successful config server and client interaction? Like I mentioned earlier, this used to work with Spring Boot 1.5.4.RELEASE and Spring Cloud Dalston.SR5, but downgrading to them is not an option.

SpringBoot 1.4 shutdown itself periodly

I got a problem that my springboot web app shutdown periodly.
I can find some exception in logs.
2017-08-16 20:43:01.376 INFO 24942 --- [ Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#6659c656: startup date [Wed Aug 09 09:09:44 EDT 2017]; root of context hierarchy
2017-08-16 20:43:01.381 INFO 24942 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Add this dependency in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

spring cloud consul deregister failed when app exit because of use spring cloud config

i use spring cloud consul as register service, spring cloud config + git as config server. an micro service app uses consul discovery configserver, then get value by propery key, also app need register service to consul for other consumers call.
dependency pom.xml:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Brixton.SR4</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-dependencies</artifactId>
<version>1.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
bootstarp.yml:
cloud:
config:
enabled: true
label: master
name: demo
discovery:
enabled: true
serviceId: CONFIG-SERVER
consul:
host: localhost
port: 8500
enabled: true
discovery:
enabled: true
healthCheckPath: /health
healthCheckInterval: 10s
tags: dev
after app start success, can get value from configserver by key, also register service to consul success, but shutdown app(control+C), ConsulLifecycle deregister not be executed. log as follow:
2016-08-05 13:22:59.675 INFO 86816 --- [ Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#c00fff0: startup date [Fri Aug 05 13:22:43 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#6989da5e
2016-08-05 13:22:59.678 INFO 86816 --- [ Thread-3] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2016-08-05 13:22:59.684 INFO 86816 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-08-05 13:22:59.685 INFO 86816 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
so i delete dependency as follow, restart app and shutdown, service deregister success. but cannot get config property.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
2016-08-05 13:24:03.671 INFO 86820 ationConfigEmbeddedWebApplicationContext - Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#52066604: startup date [Fri Aug 05 13:23:51 CST 2016]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#3315d2d7
2016-08-05 13:24:03.674 INFO 86820 o.s.c.support.DefaultLifecycleProcessor - Stopping beans in phase 0
2016-08-05 13:24:03.675 INFO 86820 o.s.c.consul.discovery.ConsulLifecycle - Deregistering service with consul: demo-server-ed3e50ef60d3f5b1295f4866c46386d1
2016-08-05 13:24:03.777 INFO 86820 o.s.b.a.e.jmx.EndpointMBeanExporter - Unregistering JMX-exposed beans on shutdown
2016-08-05 13:24:03.785 INFO 86820 o.s.b.a.e.jmx.EndpointMBeanExporter - Unregistering JMX-exposed beans
2016-08-05 13:24:03.786 INFO 86820 o.s.j.e.a.AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown
2016-08-05 13:24:03.787 INFO 86820 o.s.j.e.a.AnnotationMBeanExporter - Unregistering JMX-exposed beans
i don't know why, anything is conflict? look forwarding to any answer,thks
#spencergibb
I faced the same issue, and open an issue on spring-cloud-consul on github: https://github.com/spring-cloud/spring-cloud-consul/issues/213

Resources