Spring Boot 1.5.3 web application terminate immediately after started - maven

After started the Spring Boot Project running on 1.5.3.RELEASE the logs running then force stop
Anyone have any idea why 1.5.3 is stop, I tried 1.4.6 The started successfully
Pom.xml
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.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>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
The Application
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
#SpringBootApplication
#Controller
#EnableAutoConfiguration
public class DemoApplication {
#RequestMapping("/")
#ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Logs
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------------------------------------------------
---
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] ---------------------------------------------------------------------
---
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) > test-
compile # demo >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Workspace\spring\demo\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) < test-compile # demo <<<
[INFO]
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.3.RELEASE:run (default-cli) # demo ---
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)
2017-05-10 15:25:09.638 INFO 11112 --- [ main] com.example.DemoApplication : Starting DemoApplication on WutikornMat with PID 11112 (D:\Workspace\sp
ring\demo\target\classes started by sutee.cha in D:\Workspace\spring\demo)
2017-05-10 15:25:09.643 INFO 11112 --- [ main] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2017-05-10 15:25:09.739 INFO 11112 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigAppli
cationContext#3a723bfc: startup date [Wed May 10 15:25:09 ICT 2017]; root of context hierarchy
2017-05-10 15:25:10.599 INFO 11112 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-05-10 15:25:10.617 INFO 11112 --- [ main] com.example.DemoApplication : Started DemoApplication in 1.599 seconds (JVM running for 5.332)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.069 s
[INFO] Finished at: 2017-05-10T15:25:10+07:00
[INFO] Final Memory: 33M/398M
[INFO] ------------------------------------------------------------------------
2017-05-10 15:25:10.751 INFO 11112 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicat
ionContext#3a723bfc: startup date [Wed May 10 15:25:09 ICT 2017]; root of context hierarchy
2017-05-10 15:25:10.754 INFO 11112 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Then I run the jar via command line outside IDE
2017-05-10 15:38:57.630 INFO 7532 --- [ main] com.example.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT on WutikornMat with PID 7532 (D
:\Workspace\spring\demo\target\demo-0.0.1-SNAPSHOT.jar started by sutee.cha in D:\Workspace\spring\demo\target)
2017-05-10 15:38:57.638 INFO 7532 --- [ main] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2017-05-10 15:38:57.765 INFO 7532 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplic
ationContext#255316f2: startup date [Wed May 10 15:38:57 ICT 2017]; root of context hierarchy
2017-05-10 15:38:58.973 INFO 7532 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-05-10 15:38:58.997 INFO 7532 --- [ main] com.example.DemoApplication : Started DemoApplication in 1.888 seconds (JVM running for 2.455)
2017-05-10 15:38:59.000 INFO 7532 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicati
onContext#255316f2: startup date [Wed May 10 15:38:57 ICT 2017]; root of context hierarchy
2017-05-10 15:38:59.003 INFO 7532 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
So you can see the Setup and Example is exactly the same as spring docs
What I missed on 1.5.3
Thanks in advance

If you look at the current example there is no #SpringBootApplication annotation, but
#RestController
#EnableAutoConfiguration
public class DemoApplication {
This runs out of the box. If I start your example, I get
** WARNING ** : Your ApplicationContext is unlikely to start due to a #ComponentScan of the default package.
If I move the class from the default package to any package - let's say demo - the application starts correctly.

Related

Getting a termination after adding Springs LDAP-Core

I built a simple app with Spring Boot.
Test.java
package Test;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.scheduling.annotation.*;
#SpringBootApplication
#EnableScheduling
public class App
{
public static void main( String[] args )
{
SpringApplication.run (App.class, args);
}
}
pom.xml
<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>Test</groupId>
<artifactId>Test</artifactId>
<version>1.0</version>
<name>Test</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<fork>true</fork>
<mainClass>${start-class}</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Starts as expected.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.0.RELEASE)
2021-01-22 21:10:08.438 INFO 11932 --- [ main] Test.App : Starting App on ASPIRE with PID 11932 (/MvnTest/Test/target/classes started by ch in /data/projects/MvnTest/Test)
2021-01-22 21:10:08.441 INFO 11932 --- [ main] Test.App : No active profile set, falling back to default profiles: default
2021-01-22 21:10:09.421 INFO 11932 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-01-22 21:10:09.432 INFO 11932 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-01-22 21:10:09.432 INFO 11932 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2021-01-22 21:10:09.496 INFO 11932 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-01-22 21:10:09.496 INFO 11932 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 981 ms
2021-01-22 21:10:09.679 INFO 11932 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-22 21:10:09.820 INFO 11932 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: b1d1aca3-b55e-4d71-aac6-9e33e4d082bd
2021-01-22 21:10:09.889 INFO 11932 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#5a0bef24, org.springframework.security.web.context.SecurityContextPersistenceFilter#1bb740f2, org.springframework.security.web.header.HeaderWriterFilter#29fa6b65, org.springframework.security.web.csrf.CsrfFilter#3ac3f6f, org.springframework.security.web.authentication.logout.LogoutFilter#51b01550, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#3289079a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter#672a1c62, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter#6468a7b6, org.springframework.security.web.authentication.www.BasicAuthenticationFilter#708f018e, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#61f6d381, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#5f95f1e1, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#2f860823, org.springframework.security.web.session.SessionManagementFilter#47406941, org.springframework.security.web.access.ExceptionTranslationFilter#6504a875, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#1d247525]
2021-01-22 21:10:09.903 INFO 11932 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2021-01-22 21:10:09.953 INFO 11932 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-01-22 21:10:09.957 INFO 11932 --- [ main] Test.App : Started App in 1.876 seconds (JVM running for 2.209)
I try to add a dependency for LDAP.
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
Then it terminates immediately.
21:05:32.453 [background-preinit] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
21:05:32.456 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.17.Final
21:05:32.463 [background-preinit] DEBUG org.hibernate.validator.internal.engine.resolver.TraversableResolvers - Cannot find javax.persistence.Persistence on classpath. Assuming non JPA 2 environment. All properties will per default be traversable.
21:05:32.465 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - Trying to load META-INF/validation.xml for XML based Validator configuration.
21:05:32.466 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via TCCL
21:05:32.466 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ResourceLoaderHelper - Trying to load META-INF/validation.xml via Hibernate Validator's class loader
21:05:32.467 [background-preinit] DEBUG org.hibernate.validator.internal.xml.config.ValidationXmlParser - No META-INF/validation.xml found. Using annotation based configuration only.
21:05:32.551 [background-preinit] DEBUG org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator - Loaded expression factory via original TCCL
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator as ValidatorFactory-scoped message interpolator.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.resolver.TraverseAllTraversableResolver as ValidatorFactory-scoped traversable resolver.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.util.ExecutableParameterNameProvider as ValidatorFactory-scoped parameter name provider.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.DefaultClockProvider as ValidatorFactory-scoped clock provider.
21:05:32.555 [background-preinit] DEBUG org.hibernate.validator.internal.engine.ValidatorFactoryImpl - HV000234: Using org.hibernate.validator.internal.engine.scripting.DefaultScriptEvaluatorFactory as ValidatorFactory-scoped script evaluator factory.
Any ideas how to make it start normally?
I suspect you are have version number clashing.
when creating a spring boot project i suggest you use the spring boot initializer. Here you can select what dependencies you want. Then they generate a project for you and when you look into the pom, you will se that there is a parent pom declared at the top.
That usually looks like this and contains the version for that release of spring boot:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
</parent>
This parent is essential because spring boot is a framework, so each release of the framework includes dependencies with specific version numbers. The parent pom makes sure that all the dependencies are of version numbers that work together. You can read about how a java project in spring is setup here.
Which also means that when you declare other spring dependencies you can omit the
version numbers, since the parent pom will pick a version number that works well with that version of spring boot.
// no need for version numbering it gets fetched from the parent
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
So when you declare the ldap dependency you can also omit the version number.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-ldap</artifactId>
</dependency>
But as mentioned in the top, use the initializer to create a spring boot project. Super easy.

How to run executable-jar file in spring-boot application outside eclipse when its built using gradle?

I am able to run the spring-boot (using gradle build) application using Eclipse IDE and http://localhost:8080/ runs the app fine without any problem.
I'm now trying to run the same application using command line like this - java -jar foodapp and I get the output similar to the one I get when run in Eclipse as following:
Sandeeps-MacBook-Pro:libs sandeepamarnath$ java -jar foodapp-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-09-12 20:20:17.292 INFO 785 --- [ main] c.s.foodapp.FoodappApplication : Starting FoodappApplication on Sandeeps-MacBook-Pro.local with PID 785 (/Users/sandeepamarnath/Desktop/ShareMyRecipe-Java/foodapp/build/libs/foodapp-0.0.1-SNAPSHOT.jar started by sandeepamarnath in /Users/sandeepamarnath/Desktop/ShareMyRecipe-Java/foodapp/build/libs)
2019-09-12 20:20:17.295 INFO 785 --- [ main] c.s.foodapp.FoodappApplication : No active profile set, falling back to default profiles: default
2019-09-12 20:20:17.797 INFO 785 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-12 20:20:17.863 INFO 785 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 59ms. Found 2 repository interfaces.
2019-09-12 20:20:18.184 INFO 785 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$df477ee1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-12 20:20:18.455 INFO 785 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-09-12 20:20:18.485 INFO 785 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-12 20:20:18.485 INFO 785 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-09-12 20:20:18.737 INFO 785 --- [ main] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2019-09-12 20:20:18.901 INFO 785 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-12 20:20:18.901 INFO 785 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1572 ms
2019-09-12 20:20:19.128 INFO 785 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2019-09-12 20:20:19.868 INFO 785 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2019-09-12 20:20:19.919 INFO 785 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2019-09-12 20:20:19.992 INFO 785 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.3.10.Final}
2019-09-12 20:20:19.994 INFO 785 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2019-09-12 20:20:20.164 INFO 785 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-09-12 20:20:20.441 INFO 785 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-12 20:20:22.047 INFO 785 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-12 20:20:22.705 INFO 785 --- [ main] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter#2a79d4b1, org.springframework.security.web.context.SecurityContextPersistenceFilter#7d42c224, org.springframework.security.web.header.HeaderWriterFilter#20b12f8a, org.springframework.security.web.csrf.CsrfFilter#544820b7, org.springframework.security.web.authentication.logout.LogoutFilter#23d1e5d0, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#68ad99fe, org.springframework.security.web.savedrequest.RequestCacheAwareFilter#522a32b1, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter#5ddea849, org.springframework.security.web.authentication.AnonymousAuthenticationFilter#2e9fda69, org.springframework.security.web.session.SessionManagementFilter#2e554a3b, org.springframework.security.web.access.ExceptionTranslationFilter#2e61d218, org.springframework.security.web.access.intercept.FilterSecurityInterceptor#3f6db3fb]
2019-09-12 20:20:22.859 INFO 785 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-12 20:20:22.908 WARN 785 --- [ main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-09-12 20:20:23.140 INFO 785 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-12 20:20:23.142 INFO 785 --- [ main] c.s.foodapp.FoodappApplication : Started FoodappApplication in 21.143 seconds (JVM running for 21.485)
2019-09-12 20:20:35.404 INFO 785 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-12 20:20:35.404 INFO 785 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-09-12 20:20:35.411 INFO 785 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 7 ms
2019-09-12 20:20:35.579 INFO 785 --- [nio-8080-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator : HHH000397: Using ASTQueryTranslatorFactory
But, When I run the localhost:8080 in the browser I get error like below
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Sep 12 20:20:40 EDT 2019
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/view/index.jsp
Though I am getting the same message in eclipse and command line, when the app is run, why is that I am not able to get the browser working the second time in the command line version. Please let me know what I am doing wrong. Thanks for your time.
My gradle file contains:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
}
jar {
manifest {
attributes 'Main-Class': 'com.sharemyrecipe.foodapp.FoodappApplication.java'
}
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
apply plugin: 'io.spring.dependency-management'
group = 'com.sharemyrecipe'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// https://mvnrepository.com/artifact/jstl/jstl
compile group: 'jstl', name: 'jstl', version: '1.2'
// https://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs
compile group: 'org.springframework.security', name: 'spring-security-taglibs'
// https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compile group: 'javax.servlet', name: 'javax.servlet-api'
}
I found an answer to my question, hope it might help someone. As mentioned in Running an executable jar file built from a gradle based project
In build.gradle file I added
task runFinalJar(type: JavaExec) {
classpath = files('build/libs/foo.jar')
classpath += sourceSets.main.runtimeClasspath
main = 'com.sharemyrecipe.foodapp.FoodappApplication'
}
And in the command line (in the folder where gradlew exists), executed the command
./gradlew runFinalJar
and now it runs perfectly fine. Thanks to Eugen Martynov

Whitelabel error page on localhost:8080\sendMesssage?

I have just started Springboot with Twilio but for some reason when I run the localhost\sendMessage command I get the Whitelabel error Page. When I run the below code the test concludes successfully:
package com.example.demo
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestMapping
#RestController
public class SMSController{
#RequestMapping( "/")
fun helloSpringBoot() = "Hello Spring Boot!"
}
This is the result of the code above:
But when I run the below code with the localhost:8080\sendMessage I get the screenshot that follows the code:
package com.example.demo
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.RequestMapping
import com.twilio.http.TwilioRestClient
import com.twilio.rest.api.v2010.account.MessageCreator
import com.twilio.type.PhoneNumber
#RestController
public class SMSController{
#RequestMapping("/sendMessage")
fun sendMessage(){
val client = TwilioRestClient.Builder(
System.getenv("ACCOUNT_SID"),
System.getenv("AUTH_TOKEN")).build()
val message = MessageCreator(
PhoneNumber(System.getenv("+1..........")),
PhoneNumber("+1.........."),
"Lambda is annoying..Sigh"
).create(client)
}
}
Am I missing something?
I have added my Stack TRace:
"C:\Program Files\Java\jdk1.8.0_25\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.1\lib\idea_rt.jar=25281:C:\Program Files\JetBrains\IntelliJ IDEA 2019.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_25\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_25\jre\lib\rt.jar;C:\Users\Jevon\IdeaProjects\demo\out\production\classes;C:\Users\Jevon\IdeaProjects\demo\out\production\resources;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.twilio.sdk\twilio\7.17.9\8de7649313c8fa3dfcbd215b6c0300ca1c4184f5\twilio-7.17.9.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\2.1.4.RELEASE\a4659d55f57421a5ef122cb670b7b544ef8190e8\spring-boot-starter-web-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-json\2.1.4.RELEASE\247d7c2efae986f310a29e9fef7174adc91d0835\spring-boot-starter-json-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\2.1.4.RELEASE\8fa436ef4e273cb476d5dc3aa73701a8837460af\spring-boot-starter-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.21\d0d5ff2ac2ebd8a42697af41e20fc225a23c5d3b\kotlin-reflect-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.3.21\d0634d54452abc421db494ad32dd215e6591c49f\kotlin-stdlib-jdk8-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\18.0\cce0823396aa693798f8882e64213b1772032b09\guava-18.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\joda-time\joda-time\2.10.1\9ac3dbf89dbf2ee385185dd0cd3064fe789efee0\joda-time-2.10.1.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\io.jsonwebtoken\jjwt\0.4\61ce246d937a0fd3acf06d3bef5fc9e3933ae812\jjwt-0.4.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpclient\4.5.8\c27c9d6f15435dc2b6947112027b418b0eef32b9\httpclient-4.5.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.httpcomponents\httpcore\4.4.11\de748cf874e4e193b42eceea9fe5574fabb9d4df\httpcore-4.4.11.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\2.9.8\bcd02aa9195390e23747ed40bf76be869ad3a2fb\jackson-datatype-jdk8-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\2.9.8\28ad1bced632ba338e51c825a652f6e11a8e6eac\jackson-datatype-jsr310-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-parameter-names\2.9.8\c4eef0e6e20d60fb27af4bc4770dba7bcc3f6de6\jackson-module-parameter-names-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.9.8\11283f21cc480aa86c4df7a0a3243ec508372ed2\jackson-databind-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.9.8\f5a654e4675769c716e5b387830d19b501ca191\jackson-core-2.9.8.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.9.0\7c10d545325e3a6e72e06381afe469fd40eb701\jackson-annotations-2.9.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.xml.bind\jaxb-api\2.3.1\8531ad5ac454cc2deb9d4d32c40c4d7451939b5d\jaxb-api-2.3.1.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-tomcat\2.1.4.RELEASE\3b0c04450d86fc29c9fdad555b4555e553a4008\spring-boot-starter-tomcat-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.hibernate.validator\hibernate-validator\6.0.16.Final\ad9557c558972093c0567a2a1f224f318c00f650\hibernate-validator-6.0.16.Final.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\5.1.6.RELEASE\cf4ea53740c93e0b8ff951ef0a3eaf154c74dbd0\spring-webmvc-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\5.1.6.RELEASE\4e15a24feba0581a02efd508af03a15b05570bd4\spring-web-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\2.1.4.RELEASE\d5f8b3f7835a23b4dfd8d1489d265c1e426e317b\spring-boot-autoconfigure-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\2.1.4.RELEASE\5ad0355a8c810b32b9221b9b92746b51c983337f\spring-boot-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\2.1.4.RELEASE\2fb669a89cd65b275be20ab755c3742399395dff\spring-boot-starter-logging-2.1.4.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.3.2\934c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\5.1.6.RELEASE\7b9e80ab68ee91ca0462a0eb2c58a9d957788b\spring-context-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\5.1.6.RELEASE\a473d4bca7295f2b90522594e413f9e19107c1d2\spring-aop-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\5.1.6.RELEASE\90d2f4bf7eced108de0b5bf617abb2b13a6206a3\spring-beans-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\5.1.6.RELEASE\50fe4080029e43e7612e50fb4d7c7c43e95bf03c\spring-expression-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\5.1.6.RELEASE\9329591e728ef9844911e082e399f4fc3e3ecb37\spring-core-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.3.21\d207ce2c9bcf17dc8e51bab4dbfdac4d013e7138\kotlin-stdlib-jdk7-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.21\4bcc2012b84840e19e1e28074284cac908be0295\kotlin-stdlib-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.2.3\7c4f3c474fb2c041d8028740440937705ebb473a\logback-classic-1.2.3.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-to-slf4j\2.11.2\6d37bf7b046c0ce2669f26b99365a2cfa45c4c18\log4j-to-slf4j-2.11.2.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.23\ec62d74fe50689c28c0ff5b35d3aebcaa8b5be68\snakeyaml-1.23.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.26\8031352b2bb0a49e67818bf04c027aa92e645d5c\jul-to-slf4j-1.7.26.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.26\77100a62c2e6f04b53977b9f541044d7d722693d\slf4j-api-1.7.26.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\commons-codec\commons-codec\1.11\3acb4705652e16236558f0f4f2192cc33c3bd189\commons-codec-1.11.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.activation\javax.activation-api\1.2.0\85262acf3ca9816f9537ca47d5adeabaead7cb16\javax.activation-api-1.2.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-websocket\9.0.17\a786505cc2697f7f2d8693c0c318270cc8addd92\tomcat-embed-websocket-9.0.17.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\9.0.17\aacb92c34eb2e88f38a060c9fcaaae329a79c9ca\tomcat-embed-core-9.0.17.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\9.0.17\595fbb87426e23f27c71b267f22b6e7d2a91a2aa\tomcat-embed-el-9.0.17.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\javax.validation\validation-api\2.0.1.Final\cb855558e6271b1b32e716d24cb85c7f583ce09e\validation-api-2.0.1.Final.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.3.2.Final\3789d00e859632e6c6206adc0c71625559e6e3b0\jboss-logging-3.3.2.Final.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.4.0\291658ac2ce2476256c7115943652c0accb5c857\classmate-1.4.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jcl\5.1.6.RELEASE\a4ad3c98c7cc31357e94e12772c8e6449522bc5\spring-jcl-5.1.6.RELEASE.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.21\f30e4a9897913e53d778f564110bafa1fef46643\kotlin-stdlib-common-1.3.21.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.2.3\864344400c3d4d92dfeb0a305dc87d953677c03c\logback-core-1.2.3.jar;C:\Users\Jevon\.gradle\caches\modules-2\files-2.1\org.apache.logging.log4j\log4j-api\2.11.2\f5e9a2ffca496057d6891a3de65128efc636e26e\log4j-api-2.11.2.jar" com.example.demo.DemoApplicationKt
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.4.RELEASE)
2019-04-04 15:32:35.584 INFO 8012 --- [ main] com.example.demo.DemoApplicationKt : Starting DemoApplicationKt on Javy26 with PID 8012 (C:\Users\Jevon\IdeaProjects\demo\out\production\classes started by Jevon in C:\Users\Jevon\IdeaProjects\demo)
2019-04-04 15:32:35.596 INFO 8012 --- [ main] com.example.demo.DemoApplicationKt : No active profile set, falling back to default profiles: default
2019-04-04 15:32:35.828 WARN 8012 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2019-04-04 15:32:39.918 INFO 8012 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-04-04 15:32:39.970 INFO 8012 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-04 15:32:39.970 INFO 8012 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-04 15:32:40.214 INFO 8012 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-04 15:32:40.214 INFO 8012 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4486 ms
2019-04-04 15:32:41.275 INFO 8012 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-04 15:32:41.807 INFO 8012 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-04-04 15:32:41.811 INFO 8012 --- [ main] com.example.demo.DemoApplicationKt : Started DemoApplicationKt in 7.81 seconds (JVM running for 10.279)
2019-04-04 15:33:24.230 INFO 8012 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-04 15:33:24.230 INFO 8012 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-04-04 15:33:24.250 INFO 8012 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 20 ms
I went back through the Kotlin documentation rather than focus on the tutorial and made the necessary changes. Once that was done the code started working as it should. See changes below:
#RestController
public class SMSController{
#RequestMapping(value = ["/sendMessage"])
fun sendMessage(){
val client = TwilioRestClient.Builder("ACCOUNT_SID",
"AUTH_TOKEN").build()
val message = MessageCreator(
PhoneNumber("+1........"),
PhoneNumber("+1........"),
"Lambda is annoying..Sigh").create(client)
}
}

Embedded tomcat not launching

I wanted to upgrade to spring boot 1.5.6 from boot 1.4.3.
I created a simple web project using the spring initializer and added a simple Controller class. My pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.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>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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>
RestApplication.java
package com.djcodes.testing.rest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class RestApplication {
public static void main(String[] args) {
SpringApplication.run(RestApplication.class, args);
}
}
EmployeeController.java
package com.djcodes.testing.rest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping("/employee")
public class EmployeeController {
#RequestMapping(method = { RequestMethod.GET }, value ="/welcome")
public String welcome() {
return "Welcome to employee controller";
}
}
When I try to Launch it doenst start and just builds
$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-rest-api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) > test-compile # demo-rest-api >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # demo-rest-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # demo-rest-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # demo-rest-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/dj/Github/test-frameworks-tools/demo-rest-api/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # demo-rest-api ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) < test-compile # demo-rest-api <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.6.RELEASE:run (default-cli) # demo-rest-api ---
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
2017-08-20 16:53:09.047 INFO 7690 --- [ main] c.djcodes.testing.rest.RestApplication : Starting RestApplication on lenovo with PID 7690 (/home/dj/Github/test-frameworks-tools/demo-rest-api/target/classes started by dj in /home/dj/Github/test-frameworks-tools/demo-rest-api)
2017-08-20 16:53:09.051 INFO 7690 --- [ main] c.djcodes.testing.rest.RestApplication : No active profile set, falling back to default profiles: default
2017-08-20 16:53:09.099 INFO 7690 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#72458578: startup date [Sun Aug 20 16:53:09 IST 2017]; root of context hierarchy
2017-08-20 16:53:09.762 INFO 7690 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-08-20 16:53:09.772 INFO 7690 --- [ main] c.djcodes.testing.rest.RestApplication : Started RestApplication in 0.966 seconds (JVM running for 4.05)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.740 s
[INFO] Finished at: 2017-08-20T16:53:09+05:30
[INFO] Final Memory: 28M/275M
[INFO] ------------------------------------------------------------------------
2017-08-20 16:53:09.942 INFO 7690 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#72458578: startup date [Sun Aug 20 16:53:09 IST 2017]; root of context hierarchy
2017-08-20 16:53:09.943 INFO 7690 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Has something change in spring-boot 1.5.6? Above works fine with 1.4.3
Thanks
Looks like it was spring boot version issues. Worked with 1.5.3.RELASE

Spring boot restful web service staandalone app startup time very slow

When running my restful web service using spring boot as a standalone application, if I run it as a JAR the JVM hangs during startup for around 4-5 minutes (there is no output to console, no Spring Boot Symbol for a long time initially). The entire application takes around 26 minutest to load. If I run the application from Eclipse or package it as war and deploy it, the entire startup time is under 20 seconds.. I can't figure out what the problem is. Followed the instructions in https://spring.io/guides/gs/rest-service/
If I create the exact same spring demo application (greeting etc.) as per the link above the JVM takes around a minute to show the Spring Boot symbol. After that the application starts to load at super slow rate. Final line that I get from this simple application is:
2016-03-10 14:39:58.336 INFO 10344 --- [main] com.deepak.springbootrest.Application : Started Application in 204.826 seconds (JVM running for 254.923)
Startup time is fine when I run it from Eclipse. In eclipse, i see: 2016-03-10 14:56:56.019 INFO 24368 --- [ main] com.deepak.springbootrest.Application : Started Application in 3.452 seconds (JVM running for 4.426)
I am using JDK 1.7, which I assume should be fine.
EDIT: Application startup crawls with: C:\dev\sw\jdk\jdk1.7.0_45\bin\java.exe -Dfile.encoding=UTF-8 -jar target\spring-boot-rest-0.0.1-SNAPSHOT.jar
If I put what eclipse is using on the command line:
C:\dev\sw\jdk\jdk1.7.0_45\bin\java.exe -Dfile.encoding=UTF-8 -classpath C:\dev\bak\files\personal\train\code\tools\spring-boot-rest\target\classes;C:\Users\abrahd2.m2\repository\org\springframework\boot\spring-boot-starter-web\1.3.3.RELEASE\spring-boot-starter-web-1.3.3.RELEASE.jar;........OMITTED.....C:\Users\abrahd2.m2\repository\org\springframework\spring-expression\4.2.5.RELEASE\spring-expression-4.2.5.RELEASE.jar com.deepak.springbootrest.Application
it starts in under 4 seconds
The output from the slow-mo startup log is:
*. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.3.RELEASE)
2016-03-10 15:23:19.061 INFO 25576 --- [ main] com.deepak.springbootrest.Application : Starting Application v0.0.1-SNAPSHOT on INENABRAHD2L2C with PID 25576 (C:\dev\bak\files\personal\train\code\tools\spring-boot-rest\target\spring-boot-rest-0.0.1-SNAPSHOT.jar started by abrahd2 in C:\dev\bak\files\personal\train\code\tools\spring-boot-rest)
2016-03-10 15:23:19.625 INFO 25576 --- [ main] com.deepak.springbootrest.Application : No active profile set, falling back to default profiles: default
2016-03-10 15:23:25.529 INFO 25576 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#f1a0fad: startup date [Thu Mar 10 15:23:25 IST 2016]; root of context hierarchy
2016-03-10 15:24:14.317 INFO 25576 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2016-03-10 15:25:15.962 INFO 25576 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-03-10 15:25:17.014 INFO 25576 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-03-10 15:25:17.198 INFO 25576 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.32
2016-03-10 15:25:25.059 INFO 25576 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-03-10 15:25:25.060 INFO 25576 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 119533 ms
2016-03-10 15:25:33.350 INFO 25576 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-03-10 15:25:33.721 INFO 25576 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-03-10 15:25:33.721 INFO 25576 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-03-10 15:25:33.721 INFO 25576 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-03-10 15:25:33.721 INFO 25576 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-03-10 15:25:49.180 INFO 25576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#f1a0fad: startup date [Thu Mar 10 15:23:25 IST 2016]; root of context hierarchy
2016-03-10 15:25:59.257 INFO 25576 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting]}" onto public com.deepak.springbootrest.Greeting com.deepak.springbootrest.GreetingController.greeting(java.lang.String)
2016-03-10 15:25:59.352 INFO 25576 --- [ 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.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-03-10 15:25:59.352 INFO 25576 --- [ 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.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-03-10 15:25:59.864 INFO 25576 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-10 15:25:59.864 INFO 25576 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-10 15:26:01.305 INFO 25576 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-03-10 15:26:05.504 INFO 25576 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-03-10 15:26:10.089 INFO 25576 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-03-10 15:26:10.552 INFO 25576 --- [ main] com.deepak.springbootrest.Application : Started Application in 208.006 seconds (JVM running for 258.259)*
Adding code and pom, which is what is there in the spring guide:
package com.deepak.springbootrest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Run with mvn spring-boot:run or java -jar target/<name of jar> Run with
* http://localhost:8080/greeting
*
* #author abrahd2
*
*/
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package com.deepak.springbootrest;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
#RequestMapping("/greeting")
public Greeting greeting(#RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
package com.deepak.springbootrest;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
Pom.xml:
<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>1.3.3.RELEASE</version>
</parent>
<groupId>com.deepak.test</groupId>
<artifactId>spring-boot-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring boot rest api</name>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Resources