这是Controller类:
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);
}
}
我的文件夹结构如下: file structure
我是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
最后是我的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>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>
可能出了什么问题? 还有一个地方/视图/日志,我以后可以去检查有什么问题吗?
答案 0 :(得分:0)
我克隆了你的项目并运行它。我有几个笔记:
pom.xml
中,您添加了spring-boot-starter-security
依赖项,这将在您访问Web应用程序后创建默认登录页面。如果您在此阶段不需要安全性,请从pom.xml
中删除所有安全依赖项,或者您必须为您的应用程序提供安全配置。server.servlet.contextPath=/zooplus
,然后您可以通过以下网址访问它:http://localhost:8080/zooplus/home