Work needs to build a spring boot, through Baidu to see the micro-framework of some information, the local simple to build a
1.eclips new MAVEN project, not necessarily web engineering, new and then set up the corresponding code controller, service, boot package name, as follows
2. Configure the Pom file
<!--parent dependency-->
<parent>
<groupId>org.springframework.boot</groupId>
< Artifactid>spring-boot-starter-parent</artifactid>
<version>1.3.1.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<!--import jar package-->
< dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-web</artifactid>
</dependency>
</dependencies>
3. Start the application, implement the browser address bar input http://localhost:8080/loginUser, return OK
To start an application implementation:
@SpringbootApplication The Bean @SpringBootApplication under the package path for automatic Scan injection configuration
(scanbasepackages={) Com.linkon.ec.springboot.controller,com.linkon.ec.springboot.service "}) public
class AppStart extends springbootservletinitializer{
@Override
protected Springapplicationbuilder Configure ( Springapplicationbuilder builder) {return
builder.sources (appstart.class);
}
public static void Main (string[] args) {
//springapplication program entry
springapplication.run (Appstart.class, args) ;
}
}
Controller Segment Code
@Controller public
class Usercontroller {
@Autowired
userservice userservice;
@RequestMapping (value = "/login", method = requestmethod.get) public
String login () {return
"login";
}
@RequestMapping (value = "/loginuser", method = Requestmethod.get)
@ResponseBody public
String Loginuser () {
Userservice.loginuser ();
return Userservice.loginuser ();
}
Business Layer Code
@Service public
class UserService {public
String Loginuser () {
System.out.println ("Logi ...");
return "OK";
}
Finally in the Src/main/resources directory to create a application.properties, and configure the JSP jump path, if not configured will not find the page path, if all is
Methods that @ResponseBody annotations do not need to be configured
</pre></div><div style= "font-family: Microsoft Ya-hei; font-size:14px; line-height:21px; Widows:auto "><div style=" Background-color:inherit "><pre name=" code "class=" HTML "> spring.mvc.view.prefix:/jsp/
spring.mvc.view.suffix:.jsp
Run Main in the AppStart class. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | ////=========|_|==============|___/=/_/_/_/:: Spring Boot:: (v1.3.1.release)
2016-01-25 16:27:28.687 info 7668 --- [ main] com.linkon.ec.springboot.start.appstart : starting AppStart on lenovo-PC with PID 7668 (started by lenovo in d:\program files\workspace\springboot) 2016-01-25 16:27:28.701 info 7668 - -- [ main] Com.linkon.ec.springboot.start.appstart : no active profile set, falling back to default profiles: default 2016-01-25 16:27:28.838 info 7668 --- [ main] ationconfigembeddedwebapplicationcontext : refreshing Org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@77d0bef0: startup date [mon jan 25 16:27:28 cst 2016]; root of Context hierarchy 2016-01-25 16:27:30.117 info 7668 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean ' Beannameviewresolver ' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; Autowirecandidate=true; primary=false; factorybeanname= org.springframework.boot.autoconfigure.web.errormvcautoconfiguration$whitelabelerrorviewconfiguration; Factorymethodname=beannameviewresolver; initmethodname=null; destroymethodname= (inferred); Defined in class path resource [org/springfrAmework/boot/autoconfigure/web/errormvcautoconfiguration$whitelabelerrorviewconfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; Autowiremode=3; dependencycheck=0; autowirecandidate=true; primary=false; factorybeanname= org.springframework.boot.autoconfigure.web.webmvcautoconfiguration$webmvcautoconfigurationadapter; Factorymethodname=beannameviewresolver; initmethodname=null; destroymethodname= (inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ Webmvcautoconfiguration$webmvcautoconfigurationadapter.class]] 2016-01-25 16:27:31.342 info 7668 --- [ main] S.b.c.e.t.tomcatembeddedservletcontainer : tomcat initialized with port (s): 8080 (HTTP) 2016-01-25 16:27:31.362 info 7668 --- [ main] o.apache.catalina.core.standardservice : starting service tomcat 2016-01-25 16:27:31.363 info 7668 --- [ main] org.apache.catalina.core.standardengine : starting servlet engine: apache tomcat/8.0.30 2016-01-25 16:27:31.535 info 7668 --- [ost-startstop-1] o.a.c.c.c.[tomcat]. [localhost]. [/] : initializing spring embedded Webapplicationcontext 2016-01-25 16:27:31.536 info 7668 --- [ost-startStop-1] o.s.web.context.contextloader : root webapplicationcontext: initialization completed in&nBsp;2706 ms 2016-01-25 16:27:32.060 info 7668 --- [ost-startStop-1] O.s.b.c.e.servletregistrationbean : mapping servlet: ' Dispatcherservlet ' to [/] 2016-01-25 16:27:32.065 info 7668 --- [ost-startstop-1] o.s.b.c.embedded.filterregistrationbean : mapping filter: ' Characterencodingfilter ' to: [/*] 2016-01-25 16:27:32.065 info 7668 --- [ost-startstop-1] o.s.b.c.embedded.filterregistrationbean : mapping filter: ' Hiddenhttpmethodfilter ' to: [/*] 2016-01-25 16:27:32.065 info 7668 - -- [ost-startstop-1] o.s.b.c.embedded.filterregistrationbean : mapping filter: ' Httpputformcontentfilter ' to: [/*] 2016-01-25 16:27:32.066 info 7668 --- [ost-startstop-1] o.s.b.c.embedded.filterregistrationbean : mapping filter: ' Requestcontextfilter ' to: [/*] 2016-01-25 16:27:32.342 info 7668 --- [ main] s.w.s.m.m.a.requestmappinghandleradapter : looking for @ControllerAdvice: Org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@77d0bef0: startup date [Mon Jan 25 16:27:28 CST 2016]; root of context Hierarchy 2016-01-25 16:27:32.448 info 7668 --- [ main] s.w.s.m.m.a.requestmappinghandlermapping : mapped "{[/login],methods=[get]}" onto public java.lang.String Com.linkon.ec.springboot.controller.UserController.login () 2016-01-25 16:27:32.450 info 7668 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/loginuser],methods=[get]}" Onto public java.lang.string com.linkon.ec.springboot.controller.usercontroller.loginuser () 2016-01-25 16:27:32.456 info 7668 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/ ERROR]} " onto public org.springframework.http.ResponseEntity<java.util.Map< java.lang.string, java.lang.object>> Org.springframework.boot.autoconfigure.web.BasicErrorController.error (Javax.servlet.http.HttpServletRequest) 2016-01-25 16:27:32.457 info 7668 --- [ 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) 2016-01-25 16:27:32.512 INFO 7668 --- [ main] o.s.w.s.handler.simpleurlhandlermapping : mapped url path [/webjars/ **] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-01-25 16:27:32.512 info 7668 --- [ main] o.s.w.s.handler.simpleurlhandlermapping : mapped url path [/**] onto Handler of type [class org.springframework.web.servlet.resource.resourcehttprEquesthandler] 2016-01-25 16:27:32.608 info 7668 --- [ main] o.s.w.s.handler.simpleurlhandlermapping : mapped url path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequesthandler] 2016-01-25 16:27:32.876 INFO 7668 --- [ main] o.s.j.e.a.annotationmbeanexporter : registering beans for jmx exposure on startup 2016-01-25 16:27:32.985 info 7668 --- [ main] S.b.c.e.t.tomcatembeddedservletcontainer : tomcat started on port (s): 8080 (HTTP) 2016-01-25 16:27:32.992 info 7668 --- [ main] com.linkon.ec.springboot.start.appstart : started appstart in 4.991 seconds (jvm running for 5.453) 2016-01-25 16:27:47.107 info 7668 --- [nio-8080-exec-1] o.a.c.c.c.[tomcat]. [localhost]. [/] : initializing spring frameworkservlet ' Dispatcherservlet ' 2016-01-25 16:27:47.108 info 7668 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherservlet : frameworkservlet ' Dispatcherservlet ': initialization started 2016-01-25 16:27:47.127 info 7668 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet ' Dispatcherservlet ': &Nbsp;initialization completed in 19 ms
about using custom logback for log file configuration
1, in the Src/main/resources directory to create logback.xml files, the contents are as follows:
<!--logback configuration. http://logback.qos.ch/manual/index.html--> <configuration scan= "true" scanperiod= "seconds" > <incl Ude resource= "Org/springframework/boot/logging/logback/base.xml"/> <appender name= "INFO_FILE" Ch.qos.logback.core.rolling.RollingFileAppender "> <File>${LOG_PATH}/info.log</File> <rol Lingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <filenamepattern>${log_path}/i nfo-%d{yyyymmdd}.log.%i </fileNamePattern> <timebasedfilenamingandtriggeringpolicy class=
"Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" > <maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>2</maxHistory> </rol lingpolicy> <layout class= "Ch.qos.logback.classic.PatternLayout" > <pattern>%d{yyyy-mm-d D HH:mm:ss.
SSS} [%thread]%-5level%logger{36}-%msg%n </Pattern> </layout> </appender> <appender name= "Error_file" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <filter class= "ch.
Qos.logback.classic.filter.ThresholdFilter "> <level>ERROR</level> </filter> <File>${LOG_PATH}/error.log</File> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRo Llingpolicy "> <filenamepattern>${log_path}/error-%d{yyyymmdd}.log.%i </filenamepattern
> <timebasedfilenamingandtriggeringpolicy class= "Ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP" >
<maxFileSize>500MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>2</maxHistory> </rollingPolicy> <layout class= "Ch.qos.logback. Classic. PatternlAyout "> <Pattern>