【问题标题】:The selection cannot be run on any server选择不能在任何服务器上运行
【发布时间】:2017-05-17 12:23:52
【问题描述】:

我正在尝试学习一些有关 Spring Boot 应用程序的知识。下面是 pom.xml 文件。问题是当我尝试在服务器上运行应用程序时,我收到消息The selection cannot be run on server。不知道为什么会这样。

我检查了下面列出的几个类似的堆栈溢出问题 "The selection cannot be run on any server"Eclipse Maven Spring: Server Error when I try to Run As Server (Tomcat 7) 但找不到解决方案。

STS 的问题选项卡中没有错误或警告。此外,我已将 STS 配置为使用 Apache tomcat 版本 9。

<?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>com.blog</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</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-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

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

</project>

请建议如何在服务器上运行此应用程序

【问题讨论】:

  • 您是否尝试将其作为Spring Boot App / Java Application 运行?
  • 尝试通过右键单击项目运行它,然后单击Run As,然后单击Spring Boot Application。它运行完美。但我要求它托管在服务器上
  • 请为它创建一个单独的问题。

标签: java spring eclipse maven tomcat


【解决方案1】:

您正在处理的是一个 Spring boot 应用程序,它有一个嵌入式 battletested Tomcat 服务器。

要运行您的应用程序,您必须将其作为Java ApplicationSpring Boot App 运行。

查看thisthis 了解如何将Spring boot 应用部署为战争。

【讨论】:

  • 这没有给出解决方案,但提供了我应该前进的方向。我通过简单地添加依赖项spring-boot-starter-web 解决了它,然后当尝试以spring-boot-app 再次运行时,应用程序开始托管在tomcat 上,没有任何问题。所以感谢您指出这个方向
【解决方案2】:

在黑暗中进行真正的尝试,因为我目前无法自己尝试代码,但可能是您只需要运行标有 @SpringBootApplication 的文件,而不是寻找通过服务器选项运行。这就是我通常的做法,但我使用 Intellij,所以可能略有不同。

【讨论】:

    【解决方案3】:

    不要将应用程序作为 Java Application 运行,而是将应用程序作为 Spring Boot Application 运行

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 2012-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 2020-02-14
      • 2020-09-13
      相关资源
      最近更新 更多