-1

This is a Simple Microservice built using spring-boot. The application is working fine when I execute as Java Application. But when I run on Server i.e. Tomcat Server v8.5 the Server shows Started & Syncnorized but in console, the spring-boot logo doesn't appear and the application doesn't start. Other Projects on my IDE are working fine.

I tried following but didn't work:

1)Delete Server and add again. 2)Clean the Project using Maven. 3)Changed BuildPath Settings(JDK Version, Facets, etc).

Screenshot to refer 1) https://i.stack.imgur.com/748MP.png 2)https://i.stack.imgur.com/TKhmo.png

Main App


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class ShUsersApplication extends SpringBootServletInitializer {

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

Controller

package com.logituit.sitehawk.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.lang.NonNull;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.logituit.sitehawk.Model.Contract;
import com.logituit.sitehawk.Service.UserService;

@RestController
@RequestMapping("/sitehawk")
public class UserController {

    private UserService userService;
    private Gson gson;

    @Autowired
    public UserController(@NonNull final UserService userService, @NonNull Gson gson) {
        this.userService = userService;
        this.gson = gson;
    }

    @PostMapping("/save")
    public String saveDetails(HttpEntity<String> httpEntity) {

        final Contract contract = gson.fromJson(httpEntity.getBody(), Contract.class);
        if (contract != null) {
            userService.createTicketBySite(contract);
            return "Success";
        } else
            return "Failed";
    }

    @GetMapping("/ticketsfromsite/{siteId}")
    public List<Contract> getAllTicketsBySite(HttpEntity<String> httpEntity, @PathVariable("siteId") final int siteId) {

        return userService.getTicketsBySite(siteId);

    }

}

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.7.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.logituit.sitehawk</groupId>
    <artifactId>SH_Users</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>SH_Users</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

application.properties

#Local Database
spring.datasource.url = jdbc:mysql://localhost:3306/site_hawk
spring.datasource.username = root
spring.datasource.password = admin123
server.port=8089

Please help me how can I run my spring-boot App.I'm want to see Spring boot running on the console. But the Big Logo of Spring Boot doesn't appear on the console.

Lakk14
  • 81
  • 1
  • 5

4 Answers4

0

The normal deployment format for application containers (Tomcat included) is .war however Spring Boot by default packages a runnable jar file.

You can change the packaging format in pom.xml file.

<packaging>war</packaging>

You may also need to add an additional dependency for Tomcat specific classes.

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

Such setup should yield a .war file to $project_dir/target/classes which most servlet containers can successfully run.

käyrätorvi
  • 371
  • 1
  • 9
0

Server doesn't simple print everything in the console, since there will be a lot of applications running at the same time, the console is going to be a big confuse messy with so many "System.out", so the solution to the servers is put on log to each application. Try to find you application logs, maybe the spring logo will be there.

Be sure also that you are uploading a .war file. The jar package is for running is you pc. For Tomcat you need to send the .war file. You can simple change the packaging type in your pom.xml. Usage - Apache Maven WAR Plugin

0

To run your application in tomcat server you should exclude the embedded one via :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
      <exclusion>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-tomcat</artifactId>
       </exclusion>
     </exclusions>
</dependency>

And as käyrätorvi said package your application as war

hasnae
  • 2,137
  • 17
  • 21
0

Spring boot applications include an embedded web server and can be run in a number of ways. Tomcat is included by default which can be overridden by other servers. You can find the reference here and here.

Spring boot applications, unlike traditional java web applications, are simplified in terms of running and deploying. As a developer, you can focus on developing the core logic, exposing the endpoints etc. Once built, these applications are ready to run and do not need to be deployed on an explicit server as they run on an embedded server that comes from spring boot starter web dependency.

nakul shukla
  • 138
  • 1
  • 8