使用Spring

时间:2015-06-21 17:25:20

标签: java spring maven spring-mvc resources

使用Maven / Spring的新手,并试图创建一个简单的Web应用程序。我有一个index.html,我已经添加到src / main / resources / templates,以及主应用程序,控制器等。

我还使用黄瓜进行测试,其中一个步骤是GET" http://localhost/billparser/index"。我还在src / main / resource下设置了一个application.properties文件,条目为:

#server.contextPath=/billparser

但是我得到了这些退出行:

17:41:47.935 [main] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Trying relative path [index] against base location: ServletContext resource [/]
17:41:47.935 [main] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Trying relative path [index] against base location: class path resource [META-INF/resources/]
17:41:47.936 [main] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Trying relative path [index] against base location: class path resource [resources/]
17:41:47.936 [main] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Trying relative path [index] against base location: class path resource [static/]
17:41:47.936 [main] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Trying relative path [index] against base location: class path resource [public/]

我已经检查过了,我的index.html文件已被放入目标/类/模板中。 我在网上做了一些谷歌搜索,但我对这类东西都不熟悉,看起来有点困惑。我使用https://github.com/excellentdrums/Cucumber-JVM-Spring-MVC-Test-HTMLUnit-Demo作为模板来使其正常工作,并遵循他所做的但自己没有运气。

我已经做了一些谷歌搜索,但我还是输了。有人能指出我正确的方向吗?

谢谢。

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.tmh.bill</groupId>
<artifactId>billParser</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Bill Parser</name>
<description>Parse out a JSON to show a bill.</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.0.RC5</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test-mvc-htmlunit</artifactId>
        <version>1.0.0.M1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>1.1.6</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.1.6</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-htmlunit-driver</artifactId>
        <version>2.40.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<properties>
    <start-class>bill.Application</start-class>
    <java.version>1.7</java.version>
</properties>

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

<repositories>
    <repository>
        <id>spring-milestone</id>
        <url>http://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-milestone</id>
        <url>http://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

1 个答案:

答案 0 :(得分:0)

默认情况下,Spring Boot应用程序在端口8080上启动。此外,server.contextPath文件中的application.properties属性已注释掉,因此这不会影响您的上下文路径。只要您在控制器中映射了/index路径,您的正确网址就应为http://localhost:8080/index

您可以通过运行the example GitHub project you referenced并导航至http://localhost:8080/hello来测试此问题,这将为您提供以下信息:

enter image description here