Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.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 boot时工作,但不与Apache一起工作_Java_Spring_Spring Boot_Maven - Fatal编程技术网

Java应用程序在运行spring boot时工作,但不与Apache一起工作

Java应用程序在运行spring boot时工作,但不与Apache一起工作,java,spring,spring-boot,maven,Java,Spring,Spring Boot,Maven,当我运行/mvnw spring boot:run时,我使用so创建了一个应用程序。这些应用程序工作得很好。但是,为了能够调试我的应用程序(就像我一直对其他应用程序所做的那样),我选择了“在服务器上调试”,服务器编译成功,消息是INFORMACIÓN:Server startup in 4288 ms 但当我尝试访问应用程序时,我得到404错误 这是我的pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="

当我运行
/mvnw spring boot:run
时,我使用so创建了一个应用程序。这些应用程序工作得很好。但是,为了能够调试我的应用程序(就像我一直对其他应用程序所做的那样),我选择了“在服务器上调试”,服务器编译成功,消息是
INFORMACIÓN:Server startup in 4288 ms

但当我尝试访问应用程序时,我得到404错误

这是我的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 https://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.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.domain.app</groupId>
    <artifactId>app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>app</name>
    <description>app</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <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>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
        </dependency>
            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>compile</scope>
        </dependency>
    </dependencies>

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

</project>
我指的网址是:

http://localhost:8080/app/api/products
并且响应是
HTTP404

在构建完成后,还要在
http://localhost:8080/app
但它也得到了404

当直接使用
/mvnw spring boot:run运行时
运行良好的URL在我使用
运行服务器时也不起作用


日志里什么也没说…

我是这样理解你的问题的。您已经从spring Initializer创建了一个spring启动应用程序,并且该应用程序在命令行中成功运行,但当您尝试在服务器中部署并在调试模式下启动服务器时,该应用程序不会成功运行

您应该知道,Spring Initializer创建了一个Spring引导应用程序,它是独立的、基于Spring的生产级应用程序,您可以“直接运行”。独立意味着服务器作为依赖项合并到spring boot应用程序中,您不需要在服务器中部署

如果要在服务器中部署,需要使Spring Boot Application@SpringBootApplication类扩展SpringBootServletilizer类


@SpringBootApplication
public class DemoApplication  extends SpringBootServletInitializer {
   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(DemoApplication.class);
   }
   public static void main(String[] args) {
      SpringApplication.run(DemoApplication.class, args);
   }
}
您应该在maven中指定要运行的主类,并将打包从jar更改为war

<packaging>war</packaging>
<start-class>com.tutorialspoint.demo.DemoApplication</start-class>
战争
com.tutorialspoint.demo.DemoApplication
有关如何在服务器中部署spring引导应用程序的更多信息,请查看以下链接:


如果不需要在服务器上运行应用程序,只需调试代码即可。我建议使用eclipse或intellij。在透视图中包括spring boot dashboard,并在调试模式下启动spring boot应用程序。查看此链接以了解如何包括和使用spring boot dashboard:

在投票否决之前,您可能需要为问题添加更多详细信息。例如,成功和未成功的url、错误日志(如果有)、控制器类etcWhere是“with Apache”?当我选择run on server时,它使用eclipse Apache为应用程序提供服务。您需要了解“servlet容器”的概念,然后再也不要使用它。不要“在服务器上运行”(这意味着在外部容器中);就像普通的命令行应用程序一样运行,让Spring为您管理Web连接器。@chrylis onstrike-那么我如何使用命令行调试代码呢?太好了,这就是我想要的答案。最后一个问题,在最后,我需要将此应用程序安装在服务器(生产中),因此,使用mvn安装,如果我在这里使用spring boot工具,我将在服务器上安装war?使用mvn安装,您要做的是打包项目并将其放在maven local repository.m2文件夹中。如果您需要在服务器中部署此应用程序,则需要按照我在回答中解释的方式进行修改。然后运行mvn clean install。转到本地存储库home/@user/.m2是隐藏文件夹。找到从mvn clean install生成的war,并将其复制到服务器。您还有其他问题吗?如果您可以告诉my,不必在服务器上部署该war用于生产的其他替代方案是什么?我怎样才能在没有这些的情况下为我的应用提供服务呢?这样我就可以决定哪个选项更适合我
<packaging>war</packaging>
<start-class>com.tutorialspoint.demo.DemoApplication</start-class>