在本地主机上找不到或禁止404

时间:2019-10-07 09:56:32

标签: java spring-boot tomcat wildfly

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

我打开localhost:8080/vaadin-app/ui时得到 404未找到 。 打开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);
    }
}

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

1 个答案:

答案 0 :(得分:1)

从以下位置扩展App.java:

public class App extends SpringBootServletInitializer {

在此添加此方法:

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

最后,我建议您设置战争名称。您可以将其添加到您的 pom.xml

<finalName>vaadin-app</finalName>