Spring boot + gradle[Draft]

Source: Internet
Author: User

Getting Started document: Https://github.com/qibaoguang/Spring-Boot-Reference-Guide

Installing Gradle

Official download https://gradle.org/gradle-download/, recommended with Thunder.

Environment variable configuration: http://jingyan.baidu.com/article/4d58d541167bc69dd4e9c009.html

Let's start with spring-boot some considerations for starting a project (for beginners):

    • For convenience, please abandon the configuration XML , really jumbled
    • Full support for the annotation injection solution andjava config
    • spring-bootstart your project with a series of offers starter
    • spring-bootJust to help you better start a project instead of an application framework
    • Please use the IDEA development
Start a Web project

Plugin configuration:

IDEA's Model https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModel.html

Spring Boot plugin (gradle bootrun task only after configuration of the plugin) http://docs.spring.io/spring-boot/docs/current/reference/html/ Build-tool-plugins-gradle-plugin.html

New Folder boot mkdir boot , execute at boot root, gradle init --type java-library modify build.gradle Add dependency compile ‘org.springframework.boot:spring-boot-starter-web‘ , new Application.java :

@SpringBootApplicationpublic class Application { public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); }}

Write a simple controller.

@Controllerpublic class PublicController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; }}

bootAlmost all configurations are in application.properties , new src/main/resources/application.properties, modify port number server.port=8090 , command line start gradle bootRun view http://localhost:8090, Hello World! .
Adding additional functionality requires just adding the corresponding starter configuration, for example, some of the things that you would normally use starter :

‘org.springframework.boot:spring-boot-starter-web‘ // web项目‘org.springframework.boot:spring-boot-starter-data-jpa‘  // JPA对应DAO‘org.springframework.boot:spring-boot-starter-security‘ // 权限管理‘org.springframework.boot:spring-boot-starter-thymeleaf‘ // view层,替代JSP‘org.springframework.boot:spring-boot-devtools‘ // 开发工具,热加载

Finally, the directory structure, generally speaking:

|-- build.gradle|-- src|----|-- main|---------|-- java|--------------|-- com.project|---------------------|-- controller|---------------------|-- service|---------------------|-- repository|---------------------|-- entity|---------|-- resources|--------------|-- application.properties|--------------|-- application-dev.properties|--------------|-- application-pro.properties

I recommend this:

| --build.gradle| --src| ----|--main| ---------|--java| --------------|--com.project| ---------------------|--user| --------------------------|--controller| --------------------------|--service| --------------------------|--repository| --------------------------|--entity| ---------|--resources| --------------|--application.properties| --------------|--application-dev.properties| --------------|--application-pro.properties        

By component, easy to view code, when the project grows to a certain extent more easily split.

Unloading

Code Hot Replace method one

MVN Spring-boot:run

<plugin>        <groupId>Org.springframework.boot</groupId>        <Artifactid>Spring-boot-maven-plugin</Artifactid>        <Dependencies>          <Dependency>            <groupId>Org.springframework</groupId>            <Artifactid>springloaded</Artifactid>            <version>1.2.6.RELEASE</version>          </Dependency>        </Dependencies>        <!--<configuration> <fork>true</fork> </configuration> -      </plugin>

Code hot Load Method two:

Main method Start

-javaagent:d:/software/springloaded-1.2.6.release.jar-noverify

Template Hot Swap:

Spring.thymeleaf.cache=false

Must press CONTRL+F9, too silly.

Reference: HTTP://WWW.JIANSHU.COM/P/EC545CE19BDD A large number of examples: https://github.com/netgloo/spring-boot-samples/tree/master/ Spring-boot-basewebapp a lot of dry goods: http://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/default configuration:/http Www.tuicool.com/articles/veUjQba

Spring boot + gradle[Draft]

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.