Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.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 弹簧防尘套-“;Path index.html不以“开始”/&引用;“字符”;_Java_Angularjs_Maven_Spring Boot_Tomcat8 - Fatal编程技术网

Java 弹簧防尘套-“;Path index.html不以“开始”/&引用;“字符”;

Java 弹簧防尘套-“;Path index.html不以“开始”/&引用;“字符”;,java,angularjs,maven,spring-boot,tomcat8,Java,Angularjs,Maven,Spring Boot,Tomcat8,我正在学习SpringBoot和AngularJS,使用Eclipse作为IDE,使用Tomcat8.0.30(64位)作为容器,在Eclipse中运行。这是一个Maven项目 虽然这个应用程序非常基本和愚蠢,但我在通过浏览器访问应用程序时遇到了一个错误。问题是,如果我没有在最后输入带有斜杠(/)的URL,我就会出错。服务器日志抛出以下内容: 网址 但是,如果我像这样输入url,那么应用程序运行良好 您可能知道,spring引导应用程序不依赖web.xml。事实上,spring boot加载in

我正在学习SpringBoot和AngularJS,使用Eclipse作为IDE,使用Tomcat8.0.30(64位)作为容器,在Eclipse中运行。这是一个Maven项目

虽然这个应用程序非常基本和愚蠢,但我在通过浏览器访问应用程序时遇到了一个错误。问题是,如果我没有在最后输入带有斜杠(/)的URL,我就会出错。服务器日志抛出以下内容:

网址

但是,如果我像这样输入url,那么应用程序运行良好

您可能知道,spring引导应用程序不依赖web.xml。事实上,spring boot加载index.html作为欢迎页面,或者应该是这样

我通过部署到Tomcat容器在Eclipse外部运行应用程序。我得到了一个没有斜线的404,用斜线,它工作得很好。通过在自包含模式(embeeded Tomcat)下运行,它可以正常工作

为什么应用程序在没有斜杠的情况下不重定向到index.html?

您可以在此处找到整个应用程序(我将其标记为):

这是我的Application.java

@SpringBootApplication
@ComponentScan(basePackages = { "br.com.cinq.greet" })
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(String[] args) {
        new Application().configure(new SpringApplicationBuilder(Application.class)).run(args);
    }
}
这是我的资源配置,用于泽西岛

@Configuration
@ApplicationPath("rest")
public class Config extends ResourceConfig {

    public Config() {
        register(GreetResource.class);
    }
}
下面是GreetResource,一种典型的泽西岛资源:

@Path("/greet")
public class GreetResource {
    Logger logger = LoggerFactory.getLogger(GreetResource.class);

    // For now, store the information on a bean, in memory
    @Autowired
    Greet greet;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response greet() {
        logger.debug("Received GET requisition");
        return Response.ok().entity(greet).build();
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Response greet(Greet greet) {
        try {
            this.greet.setMessage(greet.getMessage());
            logger.info("Greeting message updated {}",this.greet.getMessage());
        } catch (Exception e) {
            logger.error("An exception occurred during Greet message update", e);
            return Response.status(Status.INTERNAL_SERVER_ERROR).entity("exception").build();
        }

        return Response.ok().build();
    }
}
也就是说,所有可能干扰该过程的Java类都在这里

以下是POM的依赖项:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>

</dependencies>

org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
春靴起跑服
org.springframework.boot
弹簧起动试验
测试
org.slf4j
slf4j api
回写
回归经典

更新

我已经安装了Tomcat 8.0.24,问题显然已经解决了

是否有新的规则,RFC,一些我不知道的关于斜杠的新东西

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>

</dependencies>