Spring boot start up failing - spring-boot

I am newbie to Spring, I have written a spring application. when I try to start the application its giving me below logs but application being shutdown.
could you please help me anyone if i am doing something wrong here ?
2017-06-01 16:39:27.187 INFO 6040 --- [ main] com.slb.sims.flows.Application : Starting Application on SLB-25QDSY1 with PID 6040 (D:\SLB\SpringPOCs\prjSpringJDBCWS\target\classes started by LTangirala in D:\SLB\SpringPOCs\prjSpringJDBCWS)
2017-06-01 16:39:27.191 INFO 6040 --- [ main] com.slb.sims.flows.Application : No active profile set, falling back to default profiles: default
2017-06-01 16:39:27.313 INFO 6040 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#2c34f934: startup date [Thu Jun 01 16:39:27 CDT 2017]; root of context hierarchy
2017-06-01 16:39:28.448 INFO 6040 --- [ main] o.s.c.s.ClassPathXmlApplicationContext : Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#2f16c6b3: startup date [Thu Jun 01 16:39:28 CDT 2017]; root of context hierarchy
2017-06-01 16:39:28.452 INFO 6040 --- [ main] o.s.b.f.xml.XmlBeanDefinitionReader : Loading XML bean definitions from class path resource [applicationContext.xml]
2017-06-01 16:39:28.592 INFO 6040 --- [ main] o.s.j.d.DriverManagerDataSource : Loaded JDBC driver: com.mysql.jdbc.Driver
2017-06-01 16:39:29.080 INFO 6040 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-06-01 16:39:29.095 INFO 6040 --- [ main] com.slb.sims.flows.Application : Started Application in 2.342 seconds (JVM running for 3.083)
2017-06-01 16:39:29.096 INFO 6040 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#2c34f934: startup date [Thu Jun 01 16:39:27 CDT 2017]; root of context hierarchy
2017-06-01 16:39:29.098 INFO 6040 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Picked up _JAVA_OPTIONS: -Xmx1024M

it doesn't have an embedded server like Tomcat in classpath. add it and it will fix the issue
for MAVEN add this dependancy in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
for Gradle (build.gradle) add
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
}

You need to add this dependency to your pom.xml.
After that it should work.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Related

Spring shell blocks tests

When I added spring shell to project
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
tests began to hangs and never ends. After stop I see in logs
2020-02-22 20:00:14.271 INFO 9812 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2020-02-22 20:00:14.933 WARN 9812 --- [ main] org.jline : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
2020-02-22 20:00:15.229 INFO 9812 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [192.168.1.10:5672]
2020-02-22 20:00:15.312 INFO 9812 --- [ main] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#4c32d208:0/SimpleConnection#608c36a6 [delegate=amqp://admin#192.168.1.10:5672/, localPort= 65404]
2020-02-22 20:00:15.401 INFO 9812 --- [ main] c.umbrella.app.BackendApplicationTests : Started BackendApplicationTests in 12.969 seconds (JVM running for 14.251)
Process finished with exit code -1
shell:>
The problem reproduces when I run tests from IDE and mvn.
How to avoid problem with tests?
I found solution, it needs to add next properties to each test:
#SpringBootTest(properties = {
InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=false",
ScriptShellApplicationRunner.SPRING_SHELL_SCRIPT_ENABLED + "=false"
})
In Spring Shell 2:
#SpringBootTest(properties = "spring.shell.interactive.enabled=false")

SpringCloud-Finchley.SR2 Eureka register-center page status 404

I imported a springcloud demo , version Finchley.SR2, after starting the application,I couldn't visit Eureka register center page,status 404.
I don't have and controller yet,Only a #SpringBootApplication
Same problem on eclipse and Idea
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Apr 17 10:46:08 CST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
If I use version Finchley.SR1 with dependency jersey-bundle 1.19, everything is normal.
Here is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>groupId</groupId>
<artifactId>register-center</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>register-center</name>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.19</version>
</dependency>
-->
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
here is the starting log that console output:
2019-04-17 10:45:55.070 INFO 6608 --- [ main] c.g.c.h.HubRegisterCenterApplication : No active profile set, falling back to default profiles: default
2019-04-17 10:45:55.930 WARN 6608 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2019-04-17 10:45:56.189 INFO 6608 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=b735a91d-6156-3751-9e56-6f2bcdd0ff57
2019-04-17 10:45:56.294 INFO 6608 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$e5276a08] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-17 10:45:56.982 INFO 6608 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8761 (http)
2019-04-17 10:45:57.007 INFO 6608 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-17 10:45:57.007 INFO 6608 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-17 10:45:57.277 INFO 6608 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-17 10:45:57.277 INFO 6608 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2190 ms
2019-04-17 10:45:57.390 WARN 6608 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-04-17 10:45:57.390 INFO 6608 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-04-17 10:45:57.408 INFO 6608 --- [ main] c.netflix.config.DynamicPropertyFactory : DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration#4af70944
2019-04-17 10:45:58.631 WARN 6608 --- [ main] o.s.c.n.a.ArchaiusAutoConfiguration : No spring.application.name found, defaulting to 'application'
2019-04-17 10:45:58.632 WARN 6608 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-04-17 10:45:58.632 INFO 6608 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-04-17 10:45:58.854 INFO 6608 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-17 10:45:59.276 WARN 6608 --- [ main] o.s.b.a.f.FreeMarkerAutoConfiguration : Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
2019-04-17 10:45:59.470 INFO 6608 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2019-04-17 10:45:59.716 INFO 6608 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-04-17 10:45:59.756 INFO 6608 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-04-17 10:45:59.758 INFO 6608 --- [ main] com.netflix.discovery.DiscoveryClient : Client configured to neither register nor query for data.
2019-04-17 10:45:59.775 INFO 6608 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1555469159773 with initial instances count: 0
2019-04-17 10:45:59.781 INFO 6608 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application UNKNOWN with eureka with status UP
2019-04-17 10:45:59.840 INFO 6608 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8761 (http) with context path ''
2019-04-17 10:45:59.844 INFO 6608 --- [ main] c.g.c.h.HubRegisterCenterApplication : Started HubRegisterCenterApplication in 6.441 seconds (JVM running for 7.261)
2019-04-17 10:46:08.612 INFO 6608 --- [nio-8761-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-17 10:46:08.612 INFO 6608 --- [nio-8761-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-04-17 10:46:08.618 INFO 6608 --- [nio-8761-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 6 ms
Here is my application.yml:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
Here is my Application class:
#SpringBootApplication
#EnableEurekaServer
public class HubRegisterCenterApplication {
public static void main(String[] args) {
SpringApplication.run(HubRegisterCenterApplication.class, args);
}
}
Problem solved.
use mvn install command,and I found that there is some problems in maven dependency jar file. delete them and re-download,problem solved
Use application.properties file instead of application.yml file.
like
spring.application.name=cart-service
server.port=8082
It worked for me.

Intellij Springboot problems on startup

I am really new with spring boot, so I started with some tutorials to create a simple Rest example (my final goal is to integrate it with mongodb, but I need to start!).
I created a new project on IntelliJ with Spring Initializr and choosed Web and Mongodb as features.
Then I added only a class,
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class HelloController {
#RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
When I run the project, the console is
2018-09-03 20:08:33.139 INFO 1363 --- [ main]
test.test.TestApplication : Starting TestApplication on
MacBook-Pro-di-Stefano.local with PID 1363
(/Users/stefanomiceli/IdeaProjects/test/target/classes started by
stefanomiceli in /Users/stefanomiceli/IdeaProjects/test)
2018-09-03 20:08:33.141 INFO 1363 --- [ main]
test.test.TestApplication : No active profile set,
falling back to default profiles: default
2018-09-03 20:08:33.173 INFO 1363 --- [ main]
ConfigServletWebServerApplicationContext : Refreshing
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#15713d56: startup date [Mon Sep 03 20:08:33 PDT 2018]; root of context hierarchy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
org.springframework.cglib.core.ReflectUtils$1
(file:/Users/stefanomiceli/.m2/repository/org/springframework/spring-
core/5.0.8.RELEASE/spring-core-5.0.8.RELEASE.jar) to method
java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of
org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further
illegal reflective access operations
WARNING: All illegal access operations will be denied in a future
release
2018-09-03 20:08:33.950 INFO 1363 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with
port(s): 8080 (http)
2018-09-03 20:08:33.969 INFO 1363 --- [ main]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-09-03 20:08:33.969 INFO 1363 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet Engine:
Apache Tomcat/8.5.32
2018-09-03 20:08:33.972 INFO 1363 --- [ost-startStop-1]
o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat
Native library which allows optimal performance in production
environments was not found on the java.library.path:
[/Users/stefanomiceli/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-09-03 20:08:34.021 INFO 1363 --- [ost-startStop-1] o.a.c.c.C.
[Tomcat].[localhost].[/] : Initializing Spring embedded
WebApplicationContext
2018-09-03 20:08:34.021 INFO 1363 --- [ost-startStop-1]
o.s.web.context.ContextLoader : Root WebApplicationContext:
initialization completed in 852 ms
2018-09-03 20:08:34.059 INFO 1363 --- [ost-startStop-1]
o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet
mapped to [/]
2018-09-03 20:08:34.061 INFO 1363 --- [ost-startStop-1]
o.s.b.w.servlet.FilterRegistrationBean : Mapping filter:
'characterEncodingFilter' to: [/*]
2018-09-03 20:08:34.062 INFO 1363 --- [ost-startStop-1]
o.s.b.w.servlet.FilterRegistrationBean : Mapping filter:
'hiddenHttpMethodFilter' to: [/*]
2018-09-03 20:08:34.062 INFO 1363 --- [ost-startStop-1]
o.s.b.w.servlet.FilterRegistrationBean : Mapping filter:
'httpPutFormContentFilter' to: [/*]
2018-09-03 20:08:34.062 INFO 1363 --- [ost-startStop-1]
o.s.b.w.servlet.FilterRegistrationBean : Mapping filter:
'requestContextFilter' to: [/*]
2018-09-03 20:08:34.143 INFO 1363 --- [ main]
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path
[/**/favicon.ico] onto handler of type [class
org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-03 20:08:34.310 INFO 1363 --- [ main]
s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for
#ControllerAdvice:
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#15713d56: startup date [Mon Sep 03 20:08:33 PDT 2018]; root of context hierarchy
2018-09-03 20:08:34.344 INFO 1363 --- [ main]
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto
public
org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>>
org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-09-03 20:08:34.345 INFO 1363 --- [ main]
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces= [text/html]}" onto public org.springframework.web.servlet.ModelAndView
org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-09-03 20:08:34.362 INFO 1363 --- [ main]
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path
[/webjars/**] onto handler of type [class
org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-03 20:08:34.362 INFO 1363 --- [ main]
o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto
handler of type [class
org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-03 20:08:34.550 INFO 1363 --- [ main]
org.mongodb.driver.cluster : Cluster created with
settings {hosts=[localhost:27017], mode=SINGLE,
requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms',
maxWaitQueueSize=500}
2018-09-03 20:08:34.582 INFO 1363 --- [localhost:27017]
org.mongodb.driver.connection : Opened connection
[connectionId{localValue:1, serverValue:55}] to localhost:27017
2018-09-03 20:08:34.585 INFO 1363 --- [localhost:27017]
org.mongodb.driver.cluster : Monitor thread successfully
connected to server with description
ServerDescription{address=localhost:27017, type=STANDALONE,
state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 0,
1]}, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216,
logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1582641}
2018-09-03 20:08:34.739 INFO 1363 --- [ main]
o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX
exposure on startup
2018-09-03 20:08:34.768 INFO 1363 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s):
8080 (http) with context path ''
2018-09-03 20:08:34.772 INFO 1363 --- [ main]
test.test.TestApplication : Started TestApplication in
1.834 seconds (JVM running for 7.413)
But when I go on localhost:8080/ I get 404 error. What did I do wrong in my helloworld? Is there anything that should I make before running the application?
You need to either
Fix the project structure in order to place the Application Entry Point (TestApplication in this case) in the base package (see image below).
Or use #ComponentScan like this (not recommended):
#SpringBootApplication
#ComponentScan("prova") // add the names of the packages where the controllers, services, repositories, etc, are going to be stored.
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
Your package structure is wrong:
prova.HelloController
test.test.TestApplication
The HelloController must be on the same level or below TestApplication.
You can do it 2 ways.
1.(preferable) Your controller package naming should be test.test.prova
i.e. Your springboot application should follow the package naming structure of Main class.
e.g. If your Main class has package name = com.test, so the controller package name should be com.test.controller
Another way is adding #ComponentScan to your Main class.
e.g.#SpringBootApplication
#ComponentScan("prova")

SpringBoot 2.0 VERY slow to start up on MacOS Sierra

Has anyone experienced a very slow startup time for SpringBoot 2.0 on MacOS Sierra?
My pom is nothing more than this (snippet):
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
It takes 22 seconds to start up:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.0.RELEASE)
2018-03-13 23:24:58.160 INFO 20517 --- [ main] jekyll.publisher.ServerApplication : Starting ServerApplication on MacBook-Pro.local with PID 20517 (/Users/workspace/jekyll-publisher/target/classes started by xxxx in /Users/workspace/jekyll-publisher)
2018-03-13 23:24:58.163 INFO 20517 --- [ main] jekyll.publisher.ServerApplication : No active profile set, falling back to default profiles: default
2018-03-13 23:24:58.190 INFO 20517 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#8909f18: startup date [Tue Mar 13 23:24:58 EDT 2018]; root of context hierarchy
2018-03-13 23:24:58.736 INFO 20517 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-03-13 23:24:58.748 INFO 20517 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-03-13 23:24:58.749 INFO 20517 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.28
2018-03-13 23:24:58.752 INFO 20517 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/Users/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
2018-03-13 23:24:58.795 INFO 20517 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-03-13 23:24:58.795 INFO 20517 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 607 ms
2018-03-13 23:24:58.878 INFO 20517 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-03-13 23:24:58.879 INFO 20517 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-03-13 23:24:58.879 INFO 20517 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-03-13 23:24:58.879 INFO 20517 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-03-13 23:24:58.879 INFO 20517 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-03-13 23:24:58.880 INFO 20517 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-03-13 23:24:58.902 INFO 20517 --- [ main] j.publisher.web.ping.PingController : Ping on the server was successful.
2018-03-13 23:24:59.044 INFO 20517 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#8909f18: startup date [Tue Mar 13 23:24:58 EDT 2018]; root of context hierarchy
2018-03-13 23:24:59.081 INFO 20517 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[POST],produces=[text/html]}" onto public java.lang.String jekyll.publisher.web.error.ForwardingErrorController.forwardOnError()
2018-03-13 23:24:59.084 INFO 20517 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/ping],methods=[GET]}" onto public jekyll.publisher.web.ping.PingResponse jekyll.publisher.web.ping.PingController.ping(javax.servlet.http.HttpSession)
2018-03-13 23:24:59.103 INFO 20517 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-13 23:24:59.104 INFO 20517 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-13 23:24:59.123 INFO 20517 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-03-13 23:24:59.134 INFO 20517 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: class path resource [static/index.html]
2018-03-13 23:24:59.225 INFO 20517 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 8edea141-84e2-4ab5-b799-0cf09c464b53
2018-03-13 23:24:59.324 INFO 20517 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher#1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#6813a331, org.springframework.security.web.context.SecurityContextPersistenceFilter#22df874e, org.springframework.security.web.header.HeaderWriterFilter#377c68c6, org.springframework.security.web.csrf.CsrfFilter#3961a41a, org.springframework.security.web.authentication.logout.LogoutFilter#537b32ef, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#607b2792, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#261d8190, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#99a65d3, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#5bdaf2ce, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#778ca8ef, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#1bd81830, org.springframework.security.web.session.SessionManagementFilter#238ad8c, org.springframework.security.web.access.ExceptionTranslationFilter#7d0332e1, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#76adb233]
2018-03-13 23:24:59.373 INFO 20517 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-03-13 23:24:59.406 INFO 20517 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-03-13 23:24:59.409 INFO 20517 --- [ main] jekyll.publisher.ServerApplication : Started ServerApplication in 16.429 seconds (JVM running for 22.012)
Any ideas?
Ok, StackOverflow is making me add "more details". Not sure what else to add here.
Ok, figured it out. It had nothing to do with Spring Boot 2.0. Just happened to coincide with that upgrade.
The real answer is from this StackOverflow:
Maven with Surefire (TestNG) is slow after update to MacOS Sierra
Set it like this
open your terminal and run hostname
$ hostname
xxx.local
modify the host config in file /etc/hosts
127.0.0.1 localhost xxx.local
::1 localhost xxx.local

Spring Boot startup slow on Raspberry PI

Using Spring Boot 2 for an IoT application, I notice that the startup time for Spring is disproportionally slow. The platform is a Raspberry PI 2B - of course, this is going to be significantly slower than a PC. For normal code execution I measure a 20x to 50x difference.
Spring boot startup time on my PC (Win10 x64): 5 seconds
Spring boot startup time on the PI (Ubuntu Server, ARM java in docker running a jar): 11 minutes
If I use the highest factor I've ever measured (50x), I would expect to see a startup time of less than half of the current state. So far, I tried:
Excluding dependencies from auto configuration (now minimal with only only spring-boot-starter-web, kotlin, undertow, webflux, reactor and kafka)
Logging on DEBUG to see what was happening during quiet periods (mostly beans being set up, nothing suspicious, though some beans take several seconds to load)
Different docker image for Java on ARM (no effect)
CPU is consistently at 100%, memory is around 20% and there is plenty of disk space
My preliminary conclusion is that loading beans eats all the CPU cycles. I imagine that initializing a bean should not take several seconds, but it does. What could be the bottleneck here? Can I get Spring to load faster in any way?
Here is the first part of the output from a PC:
2018-01-06 13:43:03.462 INFO 9144 --- [ main] c.e.b.BasestationApplicationKt : Starting BasestationApplicationKt on GPC with PID 9144 (C:\Data\Code\app\git\basestation\out\production\classes started by User in C:\Data\Code\app\git)
2018-01-06 13:43:03.471 INFO 9144 --- [ main] c.e.b.BasestationApplicationKt : The following profiles are active: dev
2018-01-06 13:43:03.637 INFO 9144 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#294e5088: startup date [Sat Jan 06 13:43:03 CET 2018]; root of context hierarchy
2018-01-06 13:43:05.578 INFO 9144 --- [ main] org.xnio : XNIO version 3.3.8.Final
2018-01-06 13:43:05.600 INFO 9144 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2018-01-06 13:43:05.695 WARN 9144 --- [ main] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2018-01-06 13:43:05.695 WARN 9144 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2018-01-06 13:43:05.721 INFO 9144 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2018-01-06 13:43:05.722 INFO 9144 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2088 ms
2018-01-06 13:43:05.851 INFO 9144 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-06 13:43:05.857 INFO 9144 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-06 13:43:07.323 INFO 9144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[GET]}" onto public com.app.basestation.model.Message com.app.basestation.BasestationController.home()
2018-01-06 13:43:07.330 INFO 9144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-01-06 13:43:07.349 INFO 9144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-01-06 13:43:07.509 INFO 9144 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#294e5088: startup date [Sat Jan 06 13:43:03 CET 2018]; root of context hierarchy
2018-01-06 13:43:08.519 INFO 9144 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-01-06 13:43:08.553 INFO 9144 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2018-01-06 13:43:08.678 INFO 9144 --- [ main] o.s.b.w.e.u.UndertowServletWebServer : Undertow started on port(s) 11112 (http)
And the output from the PI:
2018-01-06 12:48:41.689 INFO 1 --- [ main] c.e.b.BasestationApplicationKt : Starting BasestationApplicationKt on ubuntu with PID 1 (/app.jar started by root in /)
2018-01-06 12:48:42.019 INFO 1 --- [ main] c.e.b.BasestationApplicationKt : The following profiles are active: prd
2018-01-06 12:48:49.827 INFO 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#128c152: startup date [Sat Jan 06 12:48:49 UTC 2018]; root of context hierarchy
2018-01-06 12:54:05.276 INFO 1 --- [ main] org.xnio : XNIO version 3.3.8.Final
2018-01-06 12:54:08.404 INFO 1 --- [ main] org.xnio.nio : XNIO NIO Implementation Version 3.3.8.Final
2018-01-06 12:54:15.847 WARN 1 --- [ main] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2018-01-06 12:54:15.852 WARN 1 --- [ main] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2018-01-06 12:54:19.930 INFO 1 --- [ main] io.undertow.servlet : Initializing Spring embedded WebApplicationContext
2018-01-06 12:54:19.934 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 330155 ms
2018-01-06 12:54:42.544 INFO 1 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2018-01-06 12:54:43.206 INFO 1 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-01-06 12:57:18.683 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/],methods=[GET]}" onto public com.app.basestation.model.Message com.app.basestation.BasestationController.home()
2018-01-06 12:57:19.734 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-01-06 12:57:19.758 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-01-06 12:57:44.597 INFO 1 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#128c152: startup date [Sat Jan 06 12:48:49 UTC 2018]; root of context hierarchy
2018-01-06 12:59:36.677 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-01-06 12:59:37.807 INFO 1 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2018-01-06 12:59:42.664 INFO 1 --- [ main] o.s.b.w.e.u.UndertowServletWebServer : Undertow started on port(s) 11112 (http)
Update:
For those reading this, I moved back to OpenJDK in 2019 due to the new Oracle policies. What I noticed is that OpenJDK has made significant performance improvements recently. If you use OpenJDK 11 and above, it has similar performance to Oracle JDK and you can easily configure its language level to work with Java 8 code. That said, if this does not work for you, try the below.
I moved to a new image: Oracle JDK instead of OpenJDK as #snodnipper suggested.
There were several things I had to do including installing a more recent version of Java 8 than the one available in the standard repository. This is the Dockerfile that ended up working for me, and now the application starts in 2 minutes.
FROM resin/raspberrypi3-buildpack-deps:jessie-scm
ENV LANG C.UTF-8
ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
RUN ["cross-build-start"]
RUN echo "deb http://archive.raspberrypi.org/debian/ jessie main ui staging" > /etc/apt/sources.list.d/raspi.list
RUN rm -f /usr/bin/entry.sh
RUN wget -qO - http://archive.raspberrypi.org/debian/raspberrypi.gpg.key | apt-key add -
RUN { \
echo '#!/bin/bash'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home && \
chmod +x /usr/local/bin/docker-java-home
RUN apt-key adv --recv-key --keyserver keyserver.ubuntu.com C2518248EEA14886 && \
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" >> /etc/apt/sources.list.d/raspi.list
RUN set -x && \
apt-get update && \
apt-cache madison oracle-java8-installer && \
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
apt-get install -y oracle-java8-installer oracle-java8-set-default && \
rm -rf /var/lib/apt/lists/* && \
[ "$JAVA_HOME" = "$(docker-java-home)" ]
RUN [ "cross-build-end" ]
ADD build/libs/app-0.0.1-SNAPSHOT.jar /app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar

Resources