gpt4 book ai didi

java - 404 未在本地主机上找到或禁止

转载 作者:行者123 更新时间:2023-12-02 09:27:09 24 4
gpt4 key购买 nike

“我从 localhost 访问我的应用程序时遇到问题。我通过 Eclipse 在 WildFly 服务器版本 17 中添加了该项目。

当我打开localhost:8080/vaadin-app/ui时,我收到404 not found。当我打开 localhost:8080/vaadin-app 时,我得到禁止。我哪里做错了?

问题是否与web.xml 文件有关?因为我意识到,web.xml 不存在。因此我手动创建了它 web.xml

pom.xml:

<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.kamil.vaadin</groupId>
<artifactId>vaadin-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8.0</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>1.3.5.RELEASE</version><!--$NO-MVN-MAN-VER$-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
</dependencies>
<packaging>war</packaging>
</project>

Main.java:

@SpringUI(path = "/ui")
@Title("First Vaadin Web Application Page")
public class MainView extends UI{

@Override
protected void init(VaadinRequest request) {
final VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.addComponent(new com.vaadin.ui.Label("Welcome to Vaadin!!!"));
setContent(verticalLayout);
}
}

应用程序.java:

@SpringBootApplication
public class App {

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

}
}

web.xml:

<display-name>vaadin-app</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>ui</welcome-file>
</welcome-file-list>

最佳答案

将您的 App.java 扩展自:

public class App extends SpringBootServletInitializer {

并在此处添加此方法:

    @Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(App.class);
}

最后,我建议您设置 war 名称。您可以通过将其添加到您的 pom.xml 中来实现:

<finalName>vaadin-app</finalName>

关于java - 404 未在本地主机上找到或禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58267231/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com