22

Using STS, if I import the "Rest Service" Getting Started project using the latest Spring Boot and choose "Run As Spring Boot App", it starts up, then immediately shuts down.

Looking at the debug logs, Spring is for some reason deciding the project is not a web application, but I have no idea why.

If I switch from Spring Boot 1.1.1.RELEASE to 1.0.1.RELEASE, the project works as expected and the default Tomcat embedded server is found.

I can't find anything in the 1.1.1 release notes that suggests there is a config change or anything?

UPDATE: Steps to reproduce and log output

I'm running STS 3.6.0.M1 and Spring 4.0.5 and Spring Boot 1.1.1. I can easily reproduce this by doing the following:

  1. Import the REST Service Getting started app.
  2. Select "Run as Spring Boot Project"
  3. This is the output:

    :: Spring Boot ::        (v1.1.1.RELEASE)
    
    2014-06-14 11:08:34.226  INFO 47728 --- [           main] hello.Application                        : Starting Application on localhost with PID 47728 (/Users/pdrummond/src/sts/gs-rest-service-complete/target/classes started by pdrummond in /Users/pdrummond/src/sts/gs-rest-service-complete)
    2014-06-14 11:08:34.257  INFO 47728 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@802b249: startup date [Sat Jun 14 11:08:34 BST 2014]; root of context hierarchy
    2014-06-14 11:08:34.680  INFO 47728 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2014-06-14 11:08:34.908  INFO 47728 --- [           main] hello.Application                        : Started Application in 0.917 seconds (JVM running for 1.351)
    2014-06-14 11:08:36.397  INFO 47728 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@802b249: startup date [Sat Jun 14 11:08:34 BST 2014]; root of context hierarchy
    2014-06-14 11:08:36.398  INFO 47728 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
    
  4. If I edit the pom and change the spring-boot-starter-parent to 1.0.1.RELEASE it boots as expected.

UPDATE 2: Added output from --debug command

     :: Spring Boot ::        (v1.1.1.RELEASE)

    2014-06-14 19:29:03.814  INFO 986 --- [           main] hello.Application                        : Starting Application on localhost with PID 986 (/Users/pdrummond/src/sts/gs-rest-service-complete/target/classes started by pdrummond in /Users/pdrummond/src/sts/gs-rest-service-complete)
    2014-06-14 19:29:03.816 DEBUG 986 --- [           main] o.s.boot.SpringApplication               : Loading source class hello.Application
    2014-06-14 19:29:03.838  INFO 986 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@c163956: startup date [Sat Jun 14 19:29:03 BST 2014]; root of context hierarchy
    2014-06-14 19:29:04.177  INFO 986 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2014-06-14 19:29:04.346 DEBUG 986 --- [           main] utoConfigurationReportLoggingInitializer : 


    =========================
    AUTO-CONFIGURATION REPORT
    =========================


    Positive matches:
    -----------------

       PropertyPlaceholderAutoConfiguration#propertySourcesPlaceholderConfigurer
          - @ConditionalOnMissingBean (types: org.springframework.context.support.PropertySourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition)

       JacksonAutoConfiguration
          - @ConditionalOnClass classes found: com.fasterxml.jackson.databind.ObjectMapper (OnClassCondition)

       JacksonAutoConfiguration#jacksonObjectMapper
          - @ConditionalOnMissingBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) found no beans (OnBeanCondition)

       JmxAutoConfiguration
          - @ConditionalOnClass classes found: org.springframework.jmx.export.MBeanExporter (OnClassCondition)
          - SpEL expression on org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration: ${spring.jmx.enabled:true} (OnExpressionCondition)

       JmxAutoConfiguration#mbeanServer
          - @ConditionalOnMissingBean (types: javax.management.MBeanServer; SearchStrategy: all) found no beans (OnBeanCondition)

       JmxAutoConfiguration#objectNamingStrategy
          - @ConditionalOnMissingBean (types: org.springframework.jmx.export.naming.ObjectNamingStrategy; SearchStrategy: all) found no beans (OnBeanCondition)

       HttpMessageConvertersAutoConfiguration
          - @ConditionalOnClass classes found: org.springframework.http.converter.HttpMessageConverter (OnClassCondition)

       HttpMessageConvertersAutoConfiguration#messageConverters
          - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.HttpMessageConverters; SearchStrategy: all) found no beans (OnBeanCondition)

       HttpMessageConvertersAutoConfiguration.ObjectMappers
          - @ConditionalOnClass classes found: com.fasterxml.jackson.databind.ObjectMapper (OnClassCondition)

       HttpMessageConvertersAutoConfiguration.ObjectMappers#mappingJackson2HttpMessageConverter
          - @ConditionalOnMissingBean (types: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; SearchStrategy: all) found no beans (OnBeanCondition)


    Negative matches:
    -----------------

       MessageSourceAutoConfiguration
          - Bundle found for spring.messages.basename: messages (MessageSourceAutoConfiguration.ResourceBundleCondition)

       RabbitAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.amqp.rabbit.core.RabbitTemplate,com.rabbitmq.client.Channel (OnClassCondition)

       AopAutoConfiguration
          - required @ConditionalOnClass classes not found: org.aspectj.lang.annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition)

       BatchAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.batch.core.launch.JobLauncher,org.springframework.jdbc.core.JdbcOperations (OnClassCondition)

       ElasticsearchRepositoriesAutoConfiguration
          - required @ConditionalOnClass classes not found: org.elasticsearch.client.Client,org.springframework.data.elasticsearch.repository.ElasticsearchRepository (OnClassCondition)

       JpaRepositoriesAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.data.jpa.repository.JpaRepository (OnClassCondition)

       MongoRepositoriesAutoConfiguration
          - required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.repository.MongoRepository (OnClassCondition)

       RepositoryRestMvcAutoConfiguration
          - not a web application (OnWebApplicationCondition)

       SolrRepositoriesAutoConfiguration
          - required @ConditionalOnClass classes not found: org.apache.solr.client.solrj.SolrServer,org.springframework.data.solr.repository.SolrRepository (OnClassCondition)

       ElasticsearchAutoConfiguration
          - required @ConditionalOnClass classes not found: org.elasticsearch.client.Client,org.springframework.data.elasticsearch.client.TransportClientFactoryBean,org.springframework.data.elasticsearch.client.NodeClientFactoryBean (OnClassCondition)

       ElasticsearchDataAutoConfiguration
          - required @ConditionalOnClass classes not found: org.elasticsearch.client.Client,org.springframework.data.elasticsearch.core.ElasticsearchTemplate (OnClassCondition)

       FlywayAutoConfiguration
          - required @ConditionalOnClass classes not found: org.flywaydb.core.Flyway (OnClassCondition)

       FreeMarkerAutoConfiguration
          - required @ConditionalOnClass classes not found: freemarker.template.Configuration,org.springframework.ui.freemarker.FreeMarkerConfigurationFactory (OnClassCondition)

       GroovyTemplateAutoConfiguration
          - required @ConditionalOnClass classes not found: groovy.text.TemplateEngine (OnClassCondition)

       HypermediaAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.hateoas.Resource (OnClassCondition)

       IntegrationAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.integration.config.EnableIntegration (OnClassCondition)

       JacksonAutoConfiguration.JodaModuleAutoConfiguration
          - required @ConditionalOnClass classes not found: com.fasterxml.jackson.datatype.joda.JodaModule (OnClassCondition)

       JacksonAutoConfiguration.Jsr310ModuleAutoConfiguration
          - Required JVM version 1.8 or newer found 1.6 (OnJavaCondition)

       DataSourceAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)

       DataSourceTransactionManagerAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformTransactionManager (OnClassCondition)

       JmsAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.jms.core.JmsTemplate (OnClassCondition)

       ActiveMQAutoConfiguration
          - required @ConditionalOnClass classes not found: javax.jms.ConnectionFactory,org.apache.activemq.ActiveMQConnectionFactory (OnClassCondition)

       HornetQAutoConfiguration
          - required @ConditionalOnClass classes not found: javax.jms.ConnectionFactory,org.hornetq.api.jms.HornetQJMSClient (OnClassCondition)

       JmxAutoConfiguration#mbeanExporter
          - @ConditionalOnMissingBean (types: org.springframework.jmx.export.MBeanExporter; SearchStrategy: current) found the following [mbeanExporter] (OnBeanCondition)

       LiquibaseAutoConfiguration
          - required @ConditionalOnClass classes not found: liquibase.integration.spring.SpringLiquibase (OnClassCondition)

       DeviceDelegatingViewResolverAutoConfiguration
          - not a web application (OnWebApplicationCondition)

       DeviceResolverAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.mobile.device.DeviceResolverHandlerInterceptor,org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver (OnClassCondition)

       SitePreferenceAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.mobile.device.site.SitePreferenceHandlerInterceptor,org.springframework.mobile.device.site.SitePreferenceHandlerMethodArgumentResolver (OnClassCondition)

       MongoAutoConfiguration
          - required @ConditionalOnClass classes not found: com.mongodb.Mongo (OnClassCondition)

       MongoDataAutoConfiguration
          - required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.core.MongoTemplate (OnClassCondition)

       HibernateJpaAutoConfiguration
          - did not find HibernateEntityManager class (HibernateJpaAutoConfiguration.HibernateEntityManagerCondition)

       ReactorAutoConfiguration
          - required @ConditionalOnClass classes not found: reactor.spring.context.config.EnableReactor (OnClassCondition)

       RedisAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.data.redis.connection.jedis.JedisConnection,org.springframework.data.redis.core.RedisOperations,redis.clients.jedis.Jedis (OnClassCondition)

       FallbackWebSecurityAutoConfiguration
          - SpEL expression on org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration: !${security.basic.enabled:true} (OnExpressionCondition)

       SecurityAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.security.authentication.AuthenticationManager (OnClassCondition)

       FacebookAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.social.facebook.connect.FacebookConnectionFactory (OnClassCondition)

       LinkedInAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.social.linkedin.connect.LinkedInConnectionFactory (OnClassCondition)

       SocialWebAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.social.connect.web.ConnectController,org.springframework.social.config.annotation.SocialConfigurerAdapter (OnClassCondition)

       TwitterAutoConfiguration
          - required @ConditionalOnClass classes not found: org.springframework.social.twitter.connect.TwitterConnectionFactory (OnClassCondition)

       SolrAutoConfiguration
          - required @ConditionalOnClass classes not found: org.apache.solr.client.solrj.SolrServer (OnClassCondition)

       ThymeleafAutoConfiguration
          - required @ConditionalOnClass classes not found: org.thymeleaf.spring4.SpringTemplateEngine (OnClassCondition)

       VelocityAutoConfiguration
          - required @ConditionalOnClass classes not found: org.apache.velocity.app.VelocityEngine,org.springframework.ui.velocity.VelocityEngineFactory (OnClassCondition)

       DispatcherServletAutoConfiguration
          - not a web application (OnWebApplicationCondition)

       EmbeddedServletContainerAutoConfiguration
          - not a web application (OnWebApplicationCondition)

       ErrorMvcAutoConfiguration
          - required @ConditionalOnClass classes not found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet (OnClassCondition)

       MultipartAutoConfiguration
          - required @ConditionalOnClass classes not found: javax.servlet.Servlet,javax.servlet.MultipartConfigElement (OnClassCondition)

       ServerPropertiesAutoConfiguration
          - not a web application (OnWebApplicationCondition)

       WebMvcAutoConfiguration
          - not a web application (OnWebApplicationCondition)

       WebSocketAutoConfiguration
          - required @ConditionalOnClass classes not found: javax.servlet.Servlet,org.apache.catalina.startup.Tomcat,org.springframework.web.socket.WebSocketHandler,org.apache.tomcat.websocket.server.WsSci (OnClassCondition)



    2014-06-14 19:29:04.348  INFO 986 --- [           main] hello.Application                        : Started Application in 0.73 seconds (JVM running for 1.085)
    2014-06-14 19:29:06.378  INFO 986 --- [       Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@c163956: startup date [Sat Jun 14 19:29:03 BST 2014]; root of context hierarchy
    2014-06-14 19:29:06.379  INFO 986 --- [       Thread-3] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
Paul Drummond
  • 6,043
  • 6
  • 30
  • 38
  • How about pasting the log or output into your question? – Adam Gent Jun 14 '14 at 03:22
  • I assumed that wasn't necessary as it's happening with a standard sample application that is easily reproducible (for me at least), but I will add it anyway in case it provides some kind of clue that I am not seeing. – Paul Drummond Jun 14 '14 at 10:06
  • Works for me. Are you importing as Maven or Gradle project (and please try the other)? – Dave Syer Jun 14 '14 at 11:01
  • I was using Gradle at first then tried Maven and it still happened. Thanks for trying it. If it is working for you, it's probably an issue with my set-up so I will look into it in more detail. Do you know if there is any way Spring Boot will *not* default to using Tomcat when using `spring-boot-starter-web`? That seems to be what's happening, but the debug log isn't tell me why Boot is deciding it's not a web app! – Paul Drummond Jun 14 '14 at 11:32
  • You can start the app with "--debug" (or "debug=true" in application.properties). Then you will see all the autoconfig decisions. Your classpath must be messed up if tomcat is not there. – Dave Syer Jun 14 '14 at 15:20
  • Yep, already using `--debug` - there is loads of output stating `not a web application (OnWebApplicationCondition)` but I can't see anywhere that explains why that decision is made. The project has `spring-boot-starter-tomcat-1.1.1.RELEASE.jar` in the `Maven Dependencies`. I will add the full debug output to the question for completeness. – Paul Drummond Jun 14 '14 at 18:32
  • Maybe see here: https://github.com/spring-projects/spring-boot/issues/1103. That's only a problem for gradle with jetty and JSP, but you might have something similar. Try hard deleting all the project metadata and starting again with Maven. – Dave Syer Jun 16 '14 at 06:37

10 Answers10

29

I had this same issue. To make it work I had to adjust the pom.xml and comment-out the 'provided' scope for spring-boot-starter-tomcat artifact and update the dependencies.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <!--<scope>provided</scope>-->
</dependency>

Now it starts up as expected! Thanks to some of the other answers that put me on the right track.

bigMC28
  • 421
  • 4
  • 12
  • Here's the gradle solution as well: ` compile('org.springframework.boot:spring-boot-starter-tomcat') // providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')` – Dr4gon Oct 09 '16 at 14:46
  • what it doesn? does it mean that i have to install tomcat on my machine myself? i ask this, since one day you need to package it for web server. – Hassan Faghihi Oct 21 '16 at 19:09
  • This solved the problem for me too. The SpringBootApplication main was closing when launched from the IDE but worked as expected when runned with spring-boot plugin. Please consider selecting this answer as the correct one. – FrancescoM Jan 04 '17 at 12:07
  • After generating the project from [start.spring.io](https://start.spring.io/), I removed from the dependencies stack the following line: **providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')** And now it starts as expected. Thanks for the hint! – alexandrum Jul 27 '18 at 10:35
7

Check the mvn log when you execute package phase ,and make sure that the tomcat-embed-core jar is assigned into you app jar.

Boreas320
  • 850
  • 9
  • 14
6

I had the same issue where my spring-boot app shuts down immediately without any trace of tomcat being started up although I had the dependency <artifactId>spring-boot-starter-web</artifactId> included in my pom.xml. This indicates that spring-boot isn't recognizing my app as a web application.

Tried cleaning up and packaging my app again using mvn clean install utilities to verify if tomcat libraries are getting packaged into my app binary/deployable. Found the following issue (look for line starting with '[WARNING]'):

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ exam-launcher ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\XXXXX\XXXXXX\XXXX_Workspace\my-app\target\classes
[WARNING] error reading c:\.m2\org\apache\tomcat\embed\tomcat-embed-core\8.5.14\tomcat-embed-core-8.5.14.jar; invalid LOC header (bad signature)
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ exam-launcher ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Chaithu\Work_Related\Eclipse_Neon_Workspace\exam-portal-server\src\test\resources

The tomcat library I had on my local repo got corrupted (for some unknown reasons) because of which it wasn't getting included in the maven package. Deleted the corresponding folder from my local maven repo and let maven download it freshly. And it works like a charm now !!

4

All the answers suggested that tomcat is missing from it. in my case it was tagged in my pom with <scope>provided</scope> which I think i did it as i would need to run my application on another App server later. So yes that was the issue for me just another version of the same problem.

sarmahdi
  • 1,098
  • 4
  • 21
  • 61
  • 1
    Yes, in case it's not crystal clear keep the tomcat (or jetty in my case) dependency, but make sure to remove provided scope from the dependency declaration. – caprica Feb 22 '20 at 18:03
  • I have also defined the packaging as war and want to deploy it on an App server. But for testing and debugging purpose I want to run it using the main class. Can I remove the scope in my case?? – ankur_rajput May 03 '20 at 21:10
3

Just add

 spring.main.web-environment=true

in application.properties and restart.

Arundev
  • 1,388
  • 23
  • 22
2

I found the reason for this to happen. Mine was that I did not include any library which brings in the tomcat runtime with it. I included the spring-web dependency and spring-boot-starter-data-jpa(shown below) but none of these packages will bring the tomcat runtime for this app to run. So, it was auto shutdown.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-web</artifactId>
</dependency>

The solution was to change the spring-web to spring-boot-starter-web(shown below). This library brings in the tomcat library and my app started.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Vero J
  • 251
  • 2
  • 6
1

I just had the same problem and spent a while searching for a solution. I know the question is a few years old now but this might save someone else's time in future.

I got this warning message when I ran mvn clean install:

[WARNING] error reading /Users/fotouhm/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/8.5.16/tomcat-embed-core-8.5.16.jar; zip file is empty

Turns out for some reason this file was corrupted. Just go to the link below and replace it.

http://central.maven.org/maven2/org/apache/tomcat/embed/tomcat-embed-core/8.5.16/tomcat-embed-core-8.5.16.jar

MaxFot
  • 89
  • 8
0

In addition, you should check that you have at least one rest controller in your app (@RestController) and make sure you compile with spring-boot-starter-tomcat

providedRuntime ('org.springframework.boot:spring-boot-starter-tomcat')
0

In my case, I had a syntax error in application.properties:

application.password.numberOfLoginAttempts=5;

The semicolon at the end caused Spring to shutdown silently with error code 0

Fredrik Jonsén
  • 142
  • 1
  • 10
-1

In my case the log4j.properties was missing.

Andras Hatvani
  • 4,346
  • 4
  • 29
  • 45