Spring Boot Get started environment building HelloWorld

Source: Internet
Author: User
Tags bind session id tomcat apache tomcat


Say in front:

Spring boot has also been a fire, not a little familiar with the spring boot are embarrassed to go out, so I also try to see the relevant configuration of spring boot.

Overview:

Spring Boot is a new framework provided by the pivotal team designed to simplify the initial setup and development of new spring applications. The framework uses a specific approach to configuration, which eliminates the need for developers to define boilerplate configurations. In a nutshell, "Spring Boot" is a package for a quick configuration of a system framework, which encapsulates a variety of reference modules based on various types of project functionality, and the vast majority of people do not need one by one to add specific, very fine references when using them. Just add their packaged spring boot-related module plug-in. " Spring boot is not really a new frame, just like a box with a lot of detailed jars in it, so we can quote and build all kinds of frameworks by referencing this box.


Configuration tool:

1, JDK1.7

2. Maven (can also be built using non-Maven tools)

3. IDE (Eclipse, IntelliJ, or other)


Code configuration:

1. Create a new MAVEN project, which can be Web Engineering or Java Basic Engineering


2, Pom.xml in the configuration

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId> spring-boot-starter-parent</artifactid>
		<version>1.4.0.RELEASE</version>
	</parent >

	<dependencies>
		<dependency>
			<groupid>org.springframework.boot</groupid >
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</ Dependencies>



3. Create a new Java class

Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.ResponseBody;

@Controller
@EnableAutoConfiguration Public
class Samplecontroller {

	@RequestMapping ("/")
	@ Responsebody
	String Home () {
		return "Hello world!";
	}

	public static void Main (string[] args) throws Exception {
		springapplication.run (samplecontroller.class, args);
	}
}


Well, the above configuration is complete, the most simple configuration of spring boot has been completed,

Run the Main method

  . ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | ||  (_| | ) ) ) )
  '  |____| .__|_| |_|_| |_\__, |  ////=========|_|==============|___/=/_/_/_/:: Spring Boot:: (v1.4.0.release) 2017-08-30 16:05:10.511 INFO 5180---[main] c.s.project.controller.samplecontroller:starting Samplecontroller on lenovo2017 with PID 51 (E:\Eclipse4_WorkPlace\spring_boot\spring_boot_first\target\classes started by Lenovo in E:\Eclipse4_WorkPlace\ Spring_boot\spring_boot_first) 2017-08-30 16:05:10.512 INFO 5180---[main] c.s.project.controller.samplecontr           Oller:no Active profile set, falling back to default Profiles:default 2017-08-30 16:05:10.540 INFO 5180---[ Main] Ationconfigembeddedwebapplicationcontext:refreshing Org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@1b4e829:startup Date [ Wed 16:05:10 CST2017]; Root of context hierarchy 2017-08-30 16:05:11.371 INFO 5180---[main] s.b.c.e.t.tomcatembeddedservletcontaine R:tomcat initialized with Port (s): 8080 (http) 2017-08-30 16:05:11.378 INFO 5180---[main] O.apache.catalin A.core.standardservice:starting service Tomcat 2017-08-30 16:05:11.379 INFO 5180---[main] org.apache.cat Alina.core.StandardEngine:Starting Servlet engine:apache tomcat/8.5.4 2017-08-30 16:05:11.441 INFO 5180---[ost-star TSTOP-1] O.a.c.c.c.[tomcat]. [localhost]. [/AAA]: Initializing Spring embedded Webapplicationcontext 2017-08-30 16:05:11.441 INFO 5180---[ost-startstop-1] o. S.web.context.contextloader:root Webapplicationcontext:initialization completed in 902 Ms 2017-08-30 16:05:1 1.554 INFO 5180---[ost-startstop-1] o.s.b.w.servlet.servletregistrationbean:mapping servlet: ' Dispatcherservlet ' to [/] 2017-08-30 16:05:11.557 INFO 5180---[ost-startstop-1] O.s.b.w.servlet.filterregistrationbean   : Mapping filter: ' Characterencodingfilter ' to: [/*] 2017-08-30 16:05:11.557 INFO 5180---[ost-startstop-1] o.s.b.w.s Ervlet. Filterregistrationbean:mapping filter: ' Hiddenhttpmethodfilter ' to: [/*] 2017-08-30 16:05:11.558 INFO 5180---[ost-s TartStop-1] o.s.b.w.servlet.filterregistrationbean:mapping filter: ' Httpputformcontentfilter ' to: [/*] 2017-08-30 16: 05:11.558 INFO 5180---[ost-startstop-1] o.s.b.w.servlet.filterregistrationbean:mapping filter: ' Requestcontextfilte R ' to: [/*] 2017-08-30 16:05:12.066 INFO 5180---[ost-startstop-1] o.a.c.util.sessionidgeneratorbase:creation o
F SecureRandom Instance for session ID generation using [Sha1prng] took [495] milliseconds. 2017-08-30 16:05:12.301 INFO 5180---[main] s.w.s.m.m.a.requestmappinghandleradapter:looking for @Controlle radvice:org.springframework.boot.context.embedded.annotationconfigembeddedwebapplicationcontext@1b4e829: startup Date [Wed 16:05:10 CST 2017]; Root of the context HieRarchy 2017-08-30 16:05:12.346 INFO 5180---[main] s.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/]}"           Onto Java.lang.String com.sam.project.controller.SampleController.home () 2017-08-30 16:05:12.351 INFO 5180---[ 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-08-30 16:05:12.352 INFO 5180--- [main] s.w.s.m.m.a.requestmappinghandlermapping:mapped "{[/error]}" onto public org.springframework.http.Resp Onseentity<java.util.map<java.lang.string, java.lang.object>>
Org.springframework.boot.autoconfigure.web.BasicErrorController.error (Javax.servlet.http.HttpServletRequest) 2017-08-30 16:05:12.370 INFO 5180---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URLPath [/webjars/**] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-08-30 16:05:12.370 INFO 5180---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/**] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-08-30  16:05:12.397 INFO 5180---[main] o.s.w.s.handler.simpleurlhandlermapping:mapped URL path [/**/favicon.ico] onto handler of type [class Org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-08-30 16:05:12.486 INFO 5180---[main] o.s.j.e.a.annotationmbeanexporter:registering beans for JMX Exposur E on startup 2017-08-30 16:05:12.530 INFO 5180---[main] S.b.c.e.t.tomcatembeddedservletcontainer:tomcat St Arted on port (s): 8080 (http) 2017-08-30 16:05:12.532 INFO 5180---[main] C.s.project.controller.samplecontro Ller:started Samplecontroller in 2.398 seconds (JVM ruNning for 2.642)
 


You can see that the above prints a variety of information indicating that the launch was successful.


Browser access

http://localhost:8080/


You can see the output Hello world information.


Related instructions:

@EnableAutoConfiguration and Springapplication.

1, @EnableAutoConfiguration for automatic configuration. It is based on your POM configuration (which should actually be based on specific dependencies) to determine what the application is and create the appropriate environment.

In the above example, @EnableAutoConfiguration will determine that this is a Web application, so the appropriate Web environment will be created.

2. Springapplication is the class used to start the spring application from the main method. By default, it performs the following steps: Create an appropriate ApplicationContext instance (depending on classpath). Registers a commandlinepropertysource to use command-line arguments as spring properties. Refresh application context and load all singleton beans. Activates all Commandlinerunner beans.


At this point, a simple spring boot creation is completed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.