这里是控制器类:
package me.ankit.zooplus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/home")
public String home() {
return "home";
}
}
这是我的应用程序类
package me.ankit.zooplus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ZooplusApplication {
public static void main(String[] args) {
SpringApplication.run(ZooplusApplication.class, args);
}
}
我的文件夹结构如下: 文件结构
我从 maven 那里得到了这个 [从控制台复制并粘贴了几行]:
INFO 7484 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/home]}" onto public java.lang.String me.ankit.zooplus.HomeController.home()
INFO 7484 --- [lication.main()] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
INFO 7484 --- [lication.main()] me.ankit.zooplus.ZooplusApplication : Started ZooplusApplication in 10.554 seconds (JVM running for 16.948)
[INFO] BUILD SUCCESS
最后是我的绒球.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>me.ankit</groupId>
<artifactId>zooplus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>zooplus</name>
<description>zooplus: Currency Converter</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- hot swapping, disable cache for template, enable live reload -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
</project>
可能出了什么问题? 还有没有地方/视图/日志,我以后可以去检查出了什么问题?
我已经克隆了您的项目并运行了它。我确实有几个注意事项:
- 在
pom.xml
中,您添加了spring-boot-starter-security
依赖项,一旦您访问 Web 应用程序,它将创建一个默认登录页面。如果在此阶段不需要安全性,请从pom.xml
中删除所有安全依赖项,或者必须为应用程序提供安全配置。 - 访问应用程序时,请确保将"home"添加到 URL:http://localhost:8080/home 因为它映射到控制器。如果要向应用程序添加默认上下文,请将以下内容添加到application.properties:
server.servlet.contextPath=/zooplus
,然后可以通过 URL: 访问它:http://localhost:8080/zooplus/home