Introduction to Springboot development and problem summary

Source: Internet
Author: User

1. Springboot Brief Introduction (http://projects.spring.io/spring-boot/)

Today's Web projects almost all use the spring framework, and to use spring will inevitably need to configure a large number of XML configuration files, and Springboot's appearance solves this problem, a project does not even deploy to the server to run directly, as Springboot said: " Just run ".

Springboot Many of the default encoding methods are Utf-8, really welfare ah.

Org.spring 2013 's newly developed framework springboot it makes it easier to create a single project, allowing all spring-dependent programs to "jast run". Springboot offers a large number of third-party libraries so that we can start creating a spring project very easily, without even needing to configure some tedious XML configuration files

Vision:

1: Create a standalone spring app.

2: Embed Tomcat, Jetty undertow and do not need to deploy them.

3: Provide "starters" Poms to simplify MAVEN configuration

4: Automatically configure the Spring app as much as possible.

5: Provide production indicators, robust check and external configuration

6: Absolutely no code generation and XML configuration requirements

2. Simple example Demo

are based on official documents a little bit, and are now learning so much.


a simple HelloWorld directly starts the run Main method and the console I don't know what I've done, it's like I'm starting to deploy,

But it's not related to my Tomcat.


The browser can be accessed directly.

3. Detailed steps

* Note:1. Developing the first Springboot program is best built using MAVEN, and the documentation is also maven built.

2.springboot because is a newly developed framework, so only support java6 above, Java7 Best, the official recommended java8.

3. Support is required for maven3.2 and above versions.

3. The following servlet containers are supported

You can also deploy the Springboot program to all containers that support servlet3.0 or more

# Development of the first Springboot application HelloWorld

I use the MyEclipse10 Java 6 maven 3.2.3 Tomcat 7.0.55

Create a new Web project and add MAVEN support.

After next, you will choose Java EE 6.0 in the library to remember not to select, because the inside of the slf4j will be in conflict with the springboot.

#配置pom. xml

There are a lot of problems when configuring Pom. Here we remind you:

The 1.springboot Logback-classes-1.1.2.jar package has a Org.slf4j.impl package which is the package that springboot really needs and MyEclipse's own javaee6.0library also has a SLF4J package but it is not springboot need, will always report Nosuchmethod exception Getsingleton (). After a long time to find, so at first temporarily do not add javaee6.0library.

2. Here's a quick way to find the real package of the class file.

        < Span style= "Color:rgb (84, 141, 212); Font-family:simsun; " > when it is not possible to determine which package a class belongs to, can be through .class.getprotectiondomain (); To view

         < Span style= "FONT-SIZE:12PX; Color:rgb (84, 141, 212); Font-family:simsun; " > For example : package.

3. Examples of official documents are run with JAVA7. If you do not configure <java.version>1.6</java.version>, you may report an error with the version exception. What exactly is forgetting something like Mirro.minor 51.0 of 50 means jdk1.6 51 is jdk1.7

4. If the Tomcat version is also not configured, Springboot will use the 8.x version of Tomcat by default. So to add a

<tomcat.version>7.0.55</tomcat.version> to specify the version of Tomcat you are using (as determined by your catalina_home configuration).

<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>springboot</groupid>    <artifactid >springboot</artifactId>    <version>0.0.1-SNAPSHOT</version>     <packaging>war</packaging>    <name>springboot</ name>    <description />    <properties>         <project.build.sourceencoding>utf-8</ project.build.sourceencoding>        <!--  It's important to configure the Java version here, If the 1.7 version is not configurable  -->         <java.version>1.6</java.version>        <! --  Configuring your Tomcat version  -->        <tomcat.version>7.0.55 </tomcat.version>    </properties>    <build>         <plugins>             <! --If the parent inherits the Spring-boot-starter-parent, the plugin is not used              <plugin>                 <groupId>org.springframework.boot</groupId>                 <artifactid>spring-boot-maven-plugin</ Artifactid>            </plugin>            -->         </plugins>    </build>    <!--  Parent Dependency  -->    <parent>        <groupid >org.springframework.boot</groupId>        <artifactId> Spring-boot-starter-parent</artifactid>        <version> 1.2.2.release</version>    </parent>    <dependencies >        <dependency>             <!--  Import jar Packages  -->             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-web</artifactId>         </dependency>    </dependencies></project>

#编写java代码

package com.i.springboot.controller;import  org.springframework.boot.SpringApplication;import  org.springframework.boot.autoconfigure.enableautoconfiguration;import  org.springframework.web.bind.annotation.requestmapping;import  Org.springframework.web.bind.annotation.RestController, @RestController @enableautoconfigurationpublic  class firstcontroller {         @RequestMapping (value= "/")     string home () {        return  " HelloWorld ";    }        public static  Void main (String[] args)  throws Exception {         springapplication.run (Firstcontroller.class, args);    }     } 

Run the main program without error when finished running successfully. The data returned by @requestmapping can be obtained by entering the appropriate path in the browser.

Introduction to Springboot development and problem summary

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.