【发布时间】:2015-09-29 03:31:55
【问题描述】:
我已经密切关注了几个教程,但我无法开始使用最简单的应用程序。这是我目前所拥有的。
我用 Eclipse 启动了一个动态 Web 应用程序,并将它做成了一个 Maven 项目。
这是项目结构:
我的 Maven pom 是:
<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>HappySchedulerSpring</groupId>
<artifactId>HappySchedulerSpring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.2.5.RELEASE</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.2.5.RELEASE</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestone</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
Application.java 和 TweetsController.java 也很基础(直接来自 Spring 示例
package com.pistacchioso.happyscheduler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
和控制器:
package com.pistacchioso.happyscheduler;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
@EnableAutoConfiguration
public class TweetsController {
@RequestMapping("/greeting")
public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "HappyScheduler";
}
}
.jsp 文件中也没有什么特别之处:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
当我单击调试图标时,Eclipse 让我选择 Tomcat 8,没有报错,依赖项已正确解析并启动服务器,但 http:localhost:8080/greeting 一直给我 404。
有什么帮助吗?
【问题讨论】:
-
你能再检查一下端口号吗?
-
端口号正确。事实上,是 Tomcat 给了我一个 404
-
可能是网址拼错了?你能告诉我们控制台的最后几行吗?
-
我猜 HappyScheduler.jsp 需要放在 src/main/resources/templates 文件夹中..
标签: java eclipse debugging tomcat