aaaaarrrgghhh
aaaaarrrgghhh

Reputation: 407

Spring Boot application does not start in CloudFoundry

I have a Spring boot Application, built with maven, jdk1.8. It's using embedded Tomcat and jar packaging. I'm using Spring Tool Suite to push the app to CloudFoundry. I get the following messages in console after pushing:

[CONTAINER] org.apache.jasper.servlet.TldScanner               INFO  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. 
[CONTAINER] org.apache.catalina.startup.HostConfig             INFO  Deployment of web application directory /home/vcap/app/.java-buildpack/tomcat/webapps/ROOT has finished in 724 ms
[CONTAINER] org.apache.coyote.http11.Http11NioProtocol         INFO  Starting ProtocolHandler ["http-nio-8080"]
[CONTAINER] org.apache.tomcat.util.net.NioSelectorPool         INFO  Using a shared selector for servlet write/read
[CONTAINER] org.apache.catalina.startup.Catalina               INFO  Server startup in 814 ms
healthcheck passed
Container became healthy
Exit status 0
[Application Running Check] - Application appears to be running - MY-APP   

Problem is - no Spring Boot banner, no startup messages from my application - nothing. If i browse the URL, i just get a 404(which means somehow Tomcat is running!).

I tried

cf files

but realised this is on Diego, so I tried

cf ssh MY-APP

and looked in the logs directory - nothing there at all, not a single file. and

cf-events

just says that app has started.

The GUI console in CloudFoundry happily reports that its 'Running' How do i even begin to troubleshoot this?

Manifest.yml

---
applications:
- name: MY-APP
memory: 1024M
host: my-app
domain: xxx.yyy.com
services:
- p-mysql
instances: 1

application.properties

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url = jdbc:mysql://<ip_addr>:3306/<db_name>?user=<user_name>&password=<password>
spring.datasource.username = <username>
spring.datasource.password = <password>
spring.thymeleaf.cache: false

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>

<groupId>MyAPP</groupId>
<artifactId>my-app</artifactId>
<version>0.2</version>

<name>my-app</name>
<description>Attempt2</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.0.M1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

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

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

    <!--<dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency> -->

    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.3.4</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>2.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>

<repository>
    <id>sonatype-nexus-snapshots</id>
    <name>Sonatype Nexus Snapshots</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>2.1.5-SNAPSHOT</version>
        </dependency>
    </dependencies>
</dependencyManagement>

main class

package com.sa;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MyAppApplication {

   public static void main(String[] args) {
       SpringApplication.run(MyAppApplication.class, args);
   }
}

CloudFoundry env variables

{
 "staging_env_json": {},
 "running_env_json": {},
 "system_env_json": {
 "VCAP_SERVICES": {
  "p-mysql": [
    {
      "name": "p-mysql",
      "label": "p-mysql",
      "tags": [
        "mysql",
        "relational"
      ],
      "plan": "pre-existing-plan",
      "credentials": {
        "hostname": "<ip-addr>",
        "port": 3306,
        "name": "db-name",
        "username": "<username>",
        "password": "<password>",
        "uri": "mysql://<username>:<pass>@<ip_addr>:3306/<db-name>?reconnect=true",
        "jdbcUrl": "jdbc:mysql://<ip_addr>:3306/<db-name>?user=<username>&password=<pass>"
      }
    }
  ]
}
},
"application_env_json": {
"VCAP_APPLICATION": {
  "limits": {
    "mem": 1024,
    "disk": 1024,
    "fds": 16384
  },
  "application_id": "<some string>",
  "application_version": "<some other string>",
  "application_name": "my-app",
  "application_uris": [
    "my-app.xxx.yyy.com"
  ],
  "version": "2d5fd7b0-a1c2-4039-8eed-fb6e25772dee",
  "name": "my-app",
  "space_name": "xyz",
  "space_id": "<some string>",
  "uris": [
    "my-app.xxx.yyy.com"
  ],
  "users": null
   }
 }
}

Upvotes: 4

Views: 7818

Answers (1)

aaaaarrrgghhh
aaaaarrrgghhh

Reputation: 407

After ploughing away at this for half a day, i found the problem.For the impatient, it was due to this issue [spring boot and java buildpack][1]https://github.com/spring-projects/spring-boot/issues/4897

I wasn't getting anything from the STS push, so i reverted to CLI. First, mvn clean package then cf push -p PATH-to-Jar There was an entire trail of error messages (finally! something to look at!), ending with

2016-05-14T21:22:46.71+0800 [API/0]      OUT App instance exited with guid 83ec77d4-bcc5-4b12-8430-dd0a4d140b22 payload: {"instance"=>"27dc9686-1853-4 465-745e-55e450ee94c4", "index"=>0, "reason"=>"CRASHED", 
"exit_description"=>"2 error(s) occurred:\n\n* 2 error(s) occurred:\n\n* 
Exited with status 1
\n* cancelled\n* cancelled", "crash_count"=>3, "crash_timestamp"=>1463232166690142658, "version"=>"b37907a9-f4d6-4045-987c-f7bddb5e7a5c"}

The link above explains the issue and how to resolve it (use the latest java-buildpack (specify with -b switch of cf cli), so if anyone sees this Exception when pushing a spring boot app to cloud foundry, you know what could be the potential issue!

ERR Caused by: java.lang.IllegalArgumentException: Cannot instantiate 
interface org.springframework.context.ApplicationContextInitializer :org.cloudfoundry.reconfiguration.spring.CloudPropertySourceApplicationContextInitializer

Upvotes: 5

Related Questions