2 Star 1 Fork 0

zhrun8899 / learning-notes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
springBoot.md 26.22 KB
一键复制 编辑 原始数据 按行查看 历史
zhrun8899 提交于 2018-12-17 08:13 . 2018121

spring boot 安装

centos7 使用sdk安装

  1. $ curl -s get.sdkman.io | bash

  2. 根据所示执行一个osurce 语句: 如: Please open a new terminal, or run the following in the existing one:

    source "/root/.sdkman/bin/sdkman-init.sh"

  3. sdk install springboot

Spring Boot实现热部署(hot swapping)

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

运行

export MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=128M mvn spring-boot:run export JAVA_OPTS=-Xmx1024m -XX:MaxPermSize=128M gradle bootRun

配置声明

@SpringBootApplication annotation can be used to enable those three features, that is:

•@EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism •@ComponentScan: enable @Component scan on the package where the application is located (see the best practices) •@Configuration: allow to register extra beans in the context or import additional configuration classes

建立工程

包括web,jpa,security,gradle构建,并解压到目录myapp spring init -dweb,jpa,security -p war springBootTest

拼一个我自己全部要用的:

spring init -d=web,jpa,security,session,aop,mysql,cache, configuration-processor,mybatis,thymeleaf -g=com.webimation -a=SpringBootFirst -v=1.0 --package-name=com.webbimation -p=war SpringBootFirst 结果:生成项目在

spring help init Option Description


-a, --artifactId Project coordinates; infer archive ​ name (for example 'test') -b, --boot-version Spring Boot version (for example ​ '1.2.0.RELEASE') --build Build system to use (for example ​ 'maven' or 'gradle') (default: maven) -d, --dependencies Comma-separated list of dependency ​ identifiers to include in the ​ generated project --description Project description -f, --force Force overwrite of existing files --format Format of the generated content (for ​ example 'build' for a build file, ​ 'project' for a project archive) ​ (default: project) -g, --groupId Project coordinates (for example 'org. ​ test') -j, --java-version Language level (for example '1.8') -l, --language Programming language (for example ​ 'java') -n, --name Project name; infer application name -p, --packaging Project packaging (for example 'jar') --package-name Package name -t, --type Project type. Not normally needed if ​ you use --build and/or --format. ​ Check the capabilities of the ​ service (--list) for more details --target URL of the service to use (default: ​ https://start.spring.io) -v, --version Project version (for example '0.0.1- ​ SNAPSHOT') -x, --extract Extract the project archive. Inferred ​ if a location is specified without ​ an extension

examples:

To list all the capabilities of the service:
    $ spring init --list

To creates a default project:
    $ spring init

To create a web my-app.zip:
    $ spring init -d=web my-app.zip

To create a web/data-jpa gradle project unpacked:
    $ spring init -d=web,jpa --build=gradle my-dir

spring init --list . ____ _ __ _ _ /\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) ) ' |
| .__|| ||| |_, | / / / / =========||==============|/=//// :: Service capabilities :: https://start.spring.io

Supported dependencies +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+ | Id | Description ​ | Required version | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+ | activemq | Java Message Service API via Apache ActiveMQ ​ | >=1.4.0.RC1 | | activiti-basic | Activiti BPMN workflow engine ​ | | | actuator | Production ready features to help you monitor and manage your application ​ | | | actuator-docs | API documentation for the Actuator endpoints ​ | >=1.3.0.M4 | | amqp | Advanced Message Queuing Protocol via spring-rabbit ​ | | | aop | Aspect-oriented programming including spring-aop and AspectJ ​ | | | artemis | Java Message Service API via Apache Artemis ​ | >=1.3.0.M2 | | batch | Spring Batch including HSQLDB database ​ | | | cache | Spring's Cache abstraction ​ | >=1.3.0.M1 | | camel | Integration using Apache Camel ​ | | | cloud-aws | AWS native services from spring-cloud-aws ​ | >=1.2.3.RELEASE | | cloud-aws-jdbc | Relational databases on AWS with RDS and spring-cloud-aws-jdbc ​ | >=1.2.3.RELEASE | | cloud-aws-messaging | Messaging on AWS with SQS and spring-cloud-aws-messaging ​ | >=1.2.3.RELEASE | | cloud-bus-amqp | A simple control bus with AMQP and spring-cloud-bus-amqp ​ | >=1.2.3.RELEASE | | cloud-bus-kafka | A simple control bus with Kafka and spring-cloud-bus ​ | >=1.3.0.RELEASE | | cloud-cloudfoundry-discovery | Service discovery with Cloud Foundry ​ | >=1.3.0.M4 | | cloud-cluster-etcd | Leadership election and global state with Etcd and spring-cloud-cluster-etcd ​ | >=1.3.0.M4 | | cloud-cluster-hazelcast | Leadership election and global state with Hazelcast and spring-cloud-cluster-hazelcast ​ | >=1.3.0.M4 | | cloud-cluster-redis | Leadership election and global state with Redis and spring-cloud-cluster-redis ​ | >=1.3.0.M4 | | cloud-cluster-zookeeper | Leadership election and global state with Zookeeper and spring-cloud-cluster-zookeeper ​ | >=1.3.0.M4 | | cloud-config-client | spring-cloud-config Client ​ | >=1.2.3.RELEASE | | cloud-config-server | Central management for configuration via a git or svn backend ​ | >=1.2.3.RELEASE | | cloud-connectors | Simplifies connecting to services in cloud platforms, including spring-cloud-connector and spring-cloud-cloudfoundry-connector ​ | >=1.2.0.RELEASE | | cloud-contract-stub-runner | Stub Runner for HTTP/Messaging based communication ​ | >=1.4.0.RC1 | | cloud-contract-verifier | Test dependencies required for autogenerated tests ​ | >=1.4.0.RC1 | | cloud-contract-wiremock | Test dependencies required for the WireMock HTTP server ​ | >=1.4.0.RC1 | | cloud-dataflow-server-local | Local Data Flow Server implementation ​ | >=1.3.2.RELEASE and <2.0.0.M1 | | cloud-dataflow-shell | Data Flow Shell ​ | >=1.3.2.RELEASE and <2.0.0.M1 | | cloud-eureka | Service discovery using spring-cloud-netflix and Eureka ​ | >=1.2.3.RELEASE | | cloud-eureka-server | spring-cloud-netflix Eureka Server ​ | >=1.2.3.RELEASE | | cloud-feign | Declarative REST clients with spring-cloud-netflix Feign ​ | >=1.2.3.RELEASE | | cloud-hystrix | Circuit breaker with spring-cloud-netflix Hystrix ​ | >=1.2.3.RELEASE | | cloud-hystrix-dashboard | Circuit breaker dashboard with spring-cloud-netflix Hystrix ​ | >=1.2.3.RELEASE | | cloud-oauth2 | OAuth2 and distributed application patterns with spring-cloud-security ​ | >=1.2.3.RELEASE | | cloud-ribbon | Client side load balancing with spring-cloud-netflix and Ribbon ​ | >=1.2.3.RELEASE | | cloud-security | Secure load balancing and routing with spring-cloud-security ​ | >=1.2.3.RELEASE | | cloud-sleuth-stream | Marshals Spring Cloud Sleuth Spans over a Spring Cloud Stream binder ​ | >=1.3.0.M4 | | cloud-sleuth-zipkin-stream | Consumes span data in messages from Spring Cloud Sleuth Stream and writes them to a Zipkin store ​ | >=1.3.0.M4 | | cloud-starter | spring-cloud-context (e.g. Bootstrap context and @RefreshScope) ​ | >=1.2.3.RELEASE | | cloud-starter-consul-config | Configuration management with Hashicorp Consul ​ | >=1.3.0.M4 | | cloud-starter-consul-discovery | Service discovery with Hashicorp Consul ​ | >=1.3.0.M4 | | cloud-starter-sleuth | Distributed tracing via logs with spring-cloud-sleuth ​ | >=1.3.0.M4 | | cloud-starter-zipkin | Distributed tracing with an existing Zipkin installation and spring-cloud-sleuth-zipkin. Alternatively, consider Sleuth Stream. ​ | >=1.3.0.M4 | | cloud-starter-zookeeper-config | Configuration management with Zookeeper and spring-cloud-zookeeper-config ​ | >=1.3.0.M4 | | cloud-starter-zookeeper-discovery | Service discovery with Zookeeper and spring-cloud-zookeeper-discovery ​ | >=1.3.0.M4 | | cloud-stream-binder-kafka | Messaging microservices with Kafka ​ | >=1.3.0.M4 | | cloud-stream-binder-rabbit | Messaging microservices with RabbitMQ ​ | >=1.3.0.M4 | | cloud-task | Task result tracking along with integration with batch and streams ​ | >=1.3.0.RELEASE | | cloud-turbine | Circuit breaker metric aggregation using spring-cloud-netflix with Turbine and server-sent events ​ | >=1.2.3.RELEASE | | cloud-turbine-stream | Circuit breaker metric aggregation using spring-cloud-netflix with Turbine and Spring Cloud Stream (choose a specific Stream binder implementation to complement this) | >=1.3.0.M5 | | cloud-zuul | Intelligent and programmable routing with spring-cloud-netflix Zuul ​ | >=1.2.3.RELEASE | | configuration-processor | Generate metadata for your custom configuration keys ​ | >=1.2.0.RELEASE | | data-cassandra | Cassandra NoSQL Database, including spring-data-cassandra ​ | >=1.3.0.RC1 | | data-couchbase | Couchbase NoSQL database, including spring-data-couchbase ​ | >=1.4.0.M1 | | data-elasticsearch | Elasticsearch search and analytics engine including spring-data-elasticsearch ​ | | | data-gemfire | GemFire distributed data store including spring-data-gemfire ​ | >=1.1.0.RELEASE and <2.0.0.M1 | | data-jpa | Java Persistence API including spring-data-jpa, spring-orm and Hibernate ​ | | | data-jpa | Java Persistence API including spring-data-jpa, spring-orm and Hibernate ​ | | | data-ldap | LDAP support, including spring-data-ldap ​ | >=1.5.0.RC1 | | data-mongodb | MongoDB NoSQL Database, including spring-data-mongodb ​ | | | data-mongodb-reactive | MongoDB NoSQL Database, including spring-data-mongodb and the reactive driver ​ | | | data-neo4j | Neo4j NoSQL graph database, including spring-data-neo4j ​ | >=1.4.0.M2 | | data-redis | REDIS key-value data store, including spring-redis ​ | | | data-redis | REDIS key-value data store, including spring-redis ​ | | | data-rest | Exposing Spring Data repositories over REST via spring-data-rest-webmvc ​ | | | data-rest-hal | Browsing Spring Data REST repositories in your browser ​ | >=1.3.0.M1 | | data-solr | Apache Solr search platform, including spring-data-solr ​ | | | derby | Apache Derby database (with embedded support) ​ | >=1.2.2.RELEASE | | devtools | Spring Boot Development Tools ​ | >=1.3.0.M1 | | flyway | Flyway Database Migrations library ​ | | | freemarker | FreeMarker templating engine ​ | | | groovy-templates | Groovy templating engine ​ | | | h2 | H2 database (with embedded support) ​ | | | hateoas | HATEOAS-based RESTful services ​ | >=1.2.2.RELEASE | | hornetq | Java Message Service API via HornetQ ​ | >=1.1.0.RELEASE and <1.4.0.RC1 | | hsql | HSQLDB database (with embedded support) ​ | | | integration | Common spring-integration modules ​ | | | jdbc | JDBC databases ​ | | | jersey | RESTful Web Services framework ​ | >=1.2.0.RELEASE | | jooq | Persistence support using Java Object Oriented Querying ​ | >=1.3.0.M2 | | jta-atomikos | JTA distributed transactions via Atomikos ​ | >=1.2.0.M1 | | jta-bitronix | JTA distributed transactions via Bitronix ​ | >=1.2.0.M1 | | jta-narayana | JTA distributed transactions via Narayana ​ | >=1.4.0.M2 | | kafka | Kafka messaging support using Spring Kafka ​ | >=1.5.0.RC1 | | liquibase | Liquibase Database Migrations library ​ | | | lombok | Java annotation library which helps to reduce boilerplate code and code faster ​ | | | mail | javax.mail ​ | >=1.2.0.RC1 | | mobile | Simplify the development of mobile web applications with spring-mobile ​ | | | mustache | Mustache templating engine ​ | >=1.2.2.RELEASE | | mybatis | Persistence support using MyBatis ​ | | | mysql | MySQL jdbc driver ​ | | | postgresql | PostgreSQL jdbc driver ​ | | | ratpack | Spring Boot integration for the Ratpack framework ​ | >=1.2.0.RELEASE | | remote-shell | CRaSH shell integration ​ | >=1.0.0.RELEASE and <1.5.0.RC1 | | restdocs | Document RESTful services by combining hand-written and auto-generated documentation ​ | | | retry | Provide declarative retry support via spring-retry ​ | >=1.3.0.M2 | | scs-circuit-breaker | Hystrix circuit breaker on Pivotal Cloud Foundry ​ | >=1.3.0.RELEASE and <1.5.0.RC1 | | scs-config-client | Config client on Pivotal Cloud Foundry ​ | >=1.3.0.RELEASE and <1.5.0.RC1 | | scs-service-registry | Eureka service discovery on Pivotal Cloud Foundry ​ | >=1.3.0.RELEASE and <1.5.0.RC1 | | security | Secure your application via spring-security ​ | | | session | API and implementations for managing a user’s session information ​ | >=1.3.0.M2 | | social-facebook | spring-social-facebook ​ | | | social-linkedin | spring-social-linkedin ​ | | | social-twitter | spring-social-twitter ​ | | | sqlserver | Microsoft SQL Server jdbc driver ​ | >=1.5.0.RC1 | | stormpath | Stormpath default starter including Spring MVC, Thymeleaf and Spring Security ​ | >=1.5.0.RC1 and <2.0.0.M1 | | thymeleaf | Thymeleaf templating engine, including integration with Spring ​ | | | vaadin | Vaadin java web application framework ​ | >=1.2.0.RELEASE | | validation | JSR-303 validation infrastructure (already included with web) ​ | >=1.3.0.M1 | | velocity | Velocity templating engine ​ | >=1.1.6.RELEASE and <1.4.0.M2 | | web | Full-stack web development with Tomcat and Spring MVC ​ | | | web-services | Contract-first SOAP service development with Spring Web Services ​ | | | web-services | Contract-first SOAP service development with Spring Web Services ​ | | | webflux | Reactive web development with Netty and Spring WebFlux ​ | >=2.0.0.BUILD-SNAPSHOT | | websocket | Websocket development with SockJS and STOMP ​ | | | zipkin-ui | add the Zipkin UI module to the Zipkin server to get a Zipkin service that accepts Spans and provides visualization ​ | >=1.3.3.RELEASE | +-----------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+

Project types (* denotes the default) +-----------------+-----------------------------------------+-----------------------------+ | Id | Description | Tags | +-----------------+-----------------------------------------+-----------------------------+ | gradle-build | Generate a Gradle build file | build:gradle,format:build | | gradle-project | Generate a Gradle based project archive | build:gradle,format:project | | maven-build | Generate a Maven pom.xml | build:maven,format:build | | maven-project * | Generate a Maven based project archive | build:maven,format:project | +-----------------+-----------------------------------------+-----------------------------+

Parameters +-------------+------------------------------------------+------------------------------+ | Id | Description | Default value | +-------------+------------------------------------------+------------------------------+ | artifactId | project coordinates (infer archive name) | demo | | bootVersion | spring boot version | 1.5.2.RELEASE | | description | project description | Demo project for Spring Boot | | groupId | project coordinates | com.example | | javaVersion | language level | 1.8 | | language | programming language | java | | name | project name (infer application name) | demo | | packageName | root package | com.example | | packaging | project packaging | jar | | type | project type | maven-project | | version | project version | 0.0.1-SNAPSHOT

引入spring-boot依赖

Inheriting the Starter Parent ​ org.springframework.boot ​ spring-boot-starter-parent ​ 2.0.4.RELEASE 或Using Spring Boot without the Parent POM ​ ​ ​ ​ org.springframework.boot ​ spring-boot-dependencies ​ 2.0.4.RELEASE ​ pom ​ import ​ ​

1
https://gitee.com/zhrun8899/learning-notes.git
git@gitee.com:zhrun8899/learning-notes.git
zhrun8899
learning-notes
learning-notes
master

搜索帮助