前提・実現したいこと
Spring bootを使いcontrollerからHTMLを呼びブラウザ上に表示できるようにする。
発生している問題・エラーメッセージ
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Nov 17 20:30:36 JST 2019
There was an unexpected error (type=Not Found, status=404).
No message available
該当のソースコード
Java
Controllerクラス
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class Democontroller {
@RequestMapping(value="/", method=RequestMethod.GET)
public ModelAndView index(ModelAndView mav){
mav.setViewName("index2");
mav.addObject("msg", "メッセージ");
return mav;
}
}
HTML
Spring bootアプリケーション実行でのコンソール
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )__ | '_ | '| | ' / ` | \ \ \
/ __)| |)| | | | | || (| | ) ) ) )
' || .__|| ||| |_, | / / / /
=========||==============|/=////
:: Spring Boot :: (v2.2.1.RELEASE)
2019-11-17 20:41:52.920 INFO 11688 --- [ restartedMain] com.example.demo.Application : Starting Application on DESKTOP-G9PNTDK with PID 11688 (C:\Users\famil\eclipse-workspace\Spring\target\classes started by famil in C:\Users\famil\eclipse-workspace\Spring)
2019-11-17 20:41:52.923 INFO 11688 --- [ restartedMain] com.example.demo.Application : No active profile set, falling back to default profiles: default
2019-11-17 20:41:52.973 INFO 11688 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-11-17 20:41:52.974 INFO 11688 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-11-17 20:41:54.115 INFO 11688 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-11-17 20:41:54.125 INFO 11688 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-11-17 20:41:54.125 INFO 11688 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-11-17 20:41:54.239 INFO 11688 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-11-17 20:41:54.239 INFO 11688 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1265 ms
2019-11-17 20:41:54.509 INFO 11688 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-17 20:41:54.708 INFO 11688 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2019-11-17 20:41:55.071 INFO 11688 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-11-17 20:41:55.071 INFO 11688 --- [ restartedMain] com.example.demo.Application : Started Application in 2.547 seconds (JVM running for 3.725)
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>Spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Spring</name>
<description>Demo project for Spring Boot</description>
</project><properties> <java.version>13</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
試したこと
Chromeでhttp://localhost:8080/を入力
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答2件
あなたの回答
tips
プレビュー