SpringBoot学習記録(一):簡単なwebプロジェクト

8088 ワード

最近はSpring Bootを勉強しています.ネット上ではすでにとてもいいブログがあります.http://412887952-qq-com.iteye.com/category/356333?page=5
珠玉は前にいました.ここでは主に自分で実践します.
一、Springで提供される補助ツールを使用する:http://start.spring.io/を直接に作成することができます.
まず簡単なwebプロジェクトを作成して、webに依存して入力して作成して、eclipseを導入します.
SpringBoot 学习记录(一): 简单web项目_第1张图片
二、作成されたMavenプロジェクトを導入する.
1,ディレクトリ構造
SpringBoot 学习记录(一): 简单web项目_第2张图片
2,pom.xml


	4.0.0

	com.example
	demo
	0.0.1-SNAPSHOT
	jar

	demo
	Demo project for Spring Boot

	
		org.springframework.boot
		spring-boot-starter-parent
		1.3.6.RELEASE
		 
	

	
		UTF-8
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		

		
			org.springframework.boot
			spring-boot-starter-test
			test
		
	

	
		
			
				org.springframework.boot
				spring-boot-maven-plugin
			
		
	



3、新しいテストハローController
package com.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

	@RequestMapping("/sayHello")
	public String sayHello(String name){
		return "Hello: "+name;
	}
}
4、DemoAppleication.javaを起動し、コンソールの印刷開始情報を確認する.
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.8.RELEASE)

2017-04-07 10:55:35.454  INFO 5580 --- [           main] com.example.DemoApplication              : Starting DemoApplication on PC-201611261236 with PID 5580 (H:\project\demo\target\classes started by Administrator in H:\project\demo)
2017-04-07 10:55:35.472  INFO 5580 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-04-07 10:55:35.584  INFO 5580 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@574b560f: startup date [Fri Apr 07 10:55:35 CST 2017]; root of context hierarchy
2017-04-07 10:55:37.686  INFO 5580 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8088 (http)
2017-04-07 10:55:37.705  INFO 5580 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-04-07 10:55:37.707  INFO 5580 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.37
2017-04-07 10:55:37.856  INFO 5580 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/spring-boot]   : Initializing Spring embedded WebApplicationContext
2017-04-07 10:55:37.856  INFO 5580 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2286 ms
2017-04-07 10:55:38.284  INFO 5580 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2017-04-07 10:55:38.290  INFO 5580 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-04-07 10:55:38.291  INFO 5580 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-04-07 10:55:38.291  INFO 5580 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-04-07 10:55:38.291  INFO 5580 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2017-04-07 10:55:38.688  INFO 5580 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@574b560f: startup date [Fri Apr 07 10:55:35 CST 2017]; root of context hierarchy
2017-04-07 10:55:38.803  INFO 5580 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/sayHello]}" onto public java.lang.String com.example.controller.HelloController.sayHello(java.lang.String)
2017-04-07 10:55:38.808  INFO 5580 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-04-07 10:55:38.809  INFO 5580 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-04-07 10:55:38.865  INFO 5580 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-07 10:55:38.865  INFO 5580 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-07 10:55:38.937  INFO 5580 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-04-07 10:55:39.178  INFO 5580 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-04-07 10:55:39.282  INFO 5580 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8088 (http)
2017-04-07 10:55:39.290  INFO 5580 --- [           main] com.example.DemoApplication              : Started DemoApplication in 4.305 seconds (JVM running for 5.016)
、アクセステスト:http://localhost:8088/spring-boot/sayHello?name=World =======  応答結果:
ハロー:ワールド
6,注意してください.デフォルトのtomcatポート番号は8080です.ルートディレクトリから「/」が起動され、ここで変更されました.
=== appication.properties、spring_ブックはこの設定をデフォルトで読み込みます.
server.port=8088
server.context-path=/spring-boot
簡単なwebプロジェクトを構築しました.次はデータベースアクセス層に参加します.Spring Boot学習記録(二):mybaits