Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导徽标未加载到控制台上,如何在tomcat服务器上启动应用程序?_Java_Eclipse_Spring Boot_Pom.xml_Tomcat9 - Fatal编程技术网

Java Spring引导徽标未加载到控制台上,如何在tomcat服务器上启动应用程序?

Java Spring引导徽标未加载到控制台上,如何在tomcat服务器上启动应用程序?,java,eclipse,spring-boot,pom.xml,tomcat9,Java,Eclipse,Spring Boot,Pom.xml,Tomcat9,这是一个使用spring boot构建的简单微服务。当我作为Java应用程序执行时,应用程序运行良好。但是,当我在服务器(即Tomcat Server v8.5)上运行时,服务器会显示Started&Syncnorized,但在控制台中,spring boot徽标不会出现,应用程序也不会启动。我的IDE上的其他项目运行良好 我尝试了以下操作,但没有成功: 1) 删除服务器并再次添加。 2) 使用Maven清理项目。 3) 更改了构建路径设置(JDK版本、方面等) 要参考的屏幕截图 1) (二

这是一个使用spring boot构建的简单微服务。当我作为Java应用程序执行时,应用程序运行良好。但是,当我在服务器(即Tomcat Server v8.5)上运行时,服务器会显示Started&Syncnorized,但在控制台中,spring boot徽标不会出现,应用程序也不会启动。我的IDE上的其他项目运行良好

我尝试了以下操作,但没有成功:

1) 删除服务器并再次添加。 2) 使用Maven清理项目。 3) 更改了构建路径设置(JDK版本、方面等)

要参考的屏幕截图 1) (二)

主应用程序


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);
    }
}
控制器

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);

    }

}

请帮助我如何运行我的spring boot应用程序。我想看到spring boot在控制台上运行。但是Spring Boot的大徽标没有出现在控制台上。

应用程序容器(包括Tomcat)的正常部署格式是。war但是Spring Boot默认打包了一个可运行的jar文件

您可以在pom.xml文件中更改打包格式

<packaging>war</packaging>
战争
您可能还需要为Tomcat特定的类添加额外的依赖项

...
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>
。。。
org.springframework.boot
弹簧启动机tomcat
假如

这样的设置应该为$project\u dir/target/classes生成一个.war文件,大多数servlet容器都可以成功运行该文件。

服务器不会简单地在控制台中打印所有内容,因为会有很多应用程序同时运行,控制台将是一个巨大的混乱,有这么多“System.out”,因此,服务器的解决方案被记录到每个应用程序的日志中。尝试查找您的应用程序日志,可能会出现spring徽标

还要确保您正在上载
.war
文件。jar软件包用于在您的pc上运行。对于Tomcat,您需要发送
.war
文件。您可以在
pom.xml
中简单地更改打包类型。

要在tomcat server中运行应用程序,应通过以下方式排除嵌入式应用程序:

<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>

org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat

正如käyrätorvi所说,将您的应用程序打包为war,Spring boot应用程序包括一个嵌入式web服务器,可以以多种方式运行。默认情况下包含Tomcat,其他服务器可以覆盖它。您可以找到参考和


与传统的JavaWeb应用程序不同,SpringBoot应用程序在运行和部署方面得到了简化。作为开发人员,您可以专注于开发核心逻辑、公开端点等。一旦构建,这些应用程序就可以运行,并且不需要部署在显式服务器上,因为它们运行在来自spring boot starter web依赖项的嵌入式服务器上。

我应该删除此依赖项吗?````org.springframework.boot spring启动程序tomcat提供了``不一定,您可以保留它
...
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>
<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>