spring boo
Spring-boot提供了一种创建基于Spring的应用程序的快速方法。 对于下一个项目,有一些非常令人信服的理由考虑使用Spring-boot:
原因1:使用spring-boot启动程序项目进行更简单的依赖性管理。
考虑使用CR2是使用h2数据库来实现的,并考虑使用Spring-boot来启动CRUD Web应用程序所需的工作,其中Spring-Data提供了数据访问抽象。 该项目所需的Maven Pom如下:
<?xml version="1.0" encoding="UTF-8"?>
<project ...<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>0.5.0.BUILD-SNAPSHOT</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring3</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId></dependency> <dependency><groupId>org.hsqldb</groupId><artifactId>hsqldb</artifactId><scope>runtime</scope></dependency> <dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><dependency><groupId>org.hamcrest</groupId><artifactId>hamcrest-library</artifactId><scope>test</scope></dependency> </dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin> </plugins></build></project>
为了简洁起见,我删除了一些内容。
现在,将其与传统的pom.xml进行比较,其中通常会阐明所有依赖项:
.....<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.hamcrest</groupId><artifactId>hamcrest-core</artifactId><version>1.2.1</version></dependency><dependency><groupId>org.hamcrest</groupId><artifactId>hamcrest-library</artifactId><version>1.2.1</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.16</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>jcl-over-slf4j</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>${slf4j.version}</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>${aspectj.version}</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>${aspectj.version}</version></dependency><!-- dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version><scope>provided</scope></dependency --><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.0.1</version><scope>provided</scope></dependency> <dependency><groupId>net.sf.flexjson</groupId><artifactId>flexjson</artifactId><version>2.0</version></dependency><!-- Spring dependencies --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.version}</version><scope>test</scope><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-tx</artifactId><version>${spring.version}</version></dependency><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>${h2.version}</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-core</artifactId><version>${hibernate.version}</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-entitymanager</artifactId><version>${hibernate.version}</version><exclusions><exclusion><groupId>cglib</groupId><artifactId>cglib</artifactId></exclusion><exclusion><groupId>dom4j</groupId><artifactId>dom4j</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.hibernate.javax.persistence</groupId><artifactId>hibernate-jpa-2.0-api</artifactId><version>1.0.0.Final</version></dependency><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><version>4.3.0.Final</version><exclusions><exclusion><groupId>javax.xml.bind</groupId><artifactId>jaxb-api</artifactId></exclusion><exclusion><groupId>com.sun.xml.bind</groupId><artifactId>jaxb-impl</artifactId></exclusion></exclusions></dependency><dependency><groupId>javax.validation</groupId><artifactId>validation-api</artifactId><version>1.0.0.GA</version></dependency><dependency><groupId>javax.transaction</groupId><artifactId>jta</artifactId><version>1.1</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-orm</artifactId><version>${spring.version}</version></dependency><dependency><groupId>commons-pool</groupId><artifactId>commons-pool</artifactId><version>1.5.4</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.4</version></dependency> <dependency><groupId>commons-dbcp</groupId><artifactId>commons-dbcp</artifactId><version>1.3</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion><exclusion><groupId>commons-pool</groupId><artifactId>commons-pool</artifactId></exclusion><exclusion><groupId>xerces</groupId><artifactId>xerces</artifactId></exclusion><exclusion><groupId>xerces</groupId><artifactId>xercesImpl</artifactId></exclusion><exclusion><groupId>xml-apis</groupId><artifactId>xml-apis</artifactId></exclusion></exclusions></dependency><!-- Jackson JSON Processor --><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.2.1</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>2.2.1</version></dependency><dependency><groupId>com.fasterxml.jackson.module</groupId><artifactId>jackson-module-jaxb-annotations</artifactId><version>2.2.1</version></dependency><dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-core</artifactId><version>2.2.1</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.tiles</groupId><artifactId>tiles-jsp</artifactId><version>2.2.1</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${spring.version}</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>commons-digester</groupId><artifactId>commons-digester</artifactId><version>2.0</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.2.1</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.1</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><dependency><groupId>javax.el</groupId><artifactId>el-api</artifactId><version>1.0</version><scope>provided</scope></dependency><dependency><groupId>joda-time</groupId><artifactId>joda-time</artifactId><version>1.6</version></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.1</version><scope>provided</scope></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-core</artifactId><version>${spring-security.version}</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-config</artifactId><version>${spring-security.version}</version><exclusions><exclusion><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-web</artifactId><version>${spring-security.version}</version></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-taglibs</artifactId><version>${spring-security.version}</version></dependency><dependency><groupId>com.googlecode.flyway</groupId><artifactId>flyway-core</artifactId><version>1.7</version></dependency><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-jpa</artifactId><version>${spring-data-jpa.version}</version></dependency> </dependencies>
...
这确实是对Spring特定依赖项管理方式的重大改进。
原因2:具有自动配置的快速独立模式
启动可运行的Web应用程序所需要做的就是运行–“ mvn spring:boot”,其余的工作由Spring boot完成。 它提供了一种使用嵌入式tomcat或jetty容器快速运行应用程序的方法,并基于类路径中可用的库自动配置应用程序,而无需用户提供任何明确的配置,例如。 如果在类路径中找到hsqldb库,则自动将hsqldb配置为嵌入式数据库的数据源,如果在类路径中找到thymeleaf jar,则自动将thymeleaf配置为模板引擎,如果在类路径中找到了hibernate库,则自动使用hibernate作为JPA提供者。 这样可以逐步增强正在运行的应用程序的开发– Spring boot为开发人员提供了一种方法,可以快速引导应用程序并对其进行原型设计,然后用更可靠的替代方法缓慢地替换一些自动配置的组件–改为使用Postgres DB hsqldb等
原因3:固执己见的依赖性
Spring Boot提供了一套经过认真测试的,经过良好测试的依赖项,这些依赖项与Spring项目生态系统可以很好地协同工作。 例如 使用slf4j作为日志依赖项进行logback,使用Servlet 3.0+ API,使用Jackson 2.2进行json处理,使用thymeleaf进行网页模板化。
结论:
Spring-boot项目仍处于繁重的开发过程中,但是即使在目前的状态下,它也具有使用Spring伞项目大大简化应用程序开发方面的巨大潜力。
这是一个使用Spring-boot的小型参考应用程序– https://github.com/bijukunjummen/spring-boot-mvc-test.git
翻译自: https://www.javacodegeeks.com/2013/09/reasons-to-consider-spring-boot-for-your-next-spring-based-application.html
spring boo