如何在Spring-boot应用程序

时间:2018-06-18 20:58:28

标签: spring-boot spring-jdbc spring-boot-test

我们的团队刚刚继承了一个Spring-boot应用程序(R1.4.3),它有以下pom.xml(摘录):

<groupId>SpreadSheetUploadWeb</groupId>
    <artifactId>SpreadSheetUploadWeb</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>

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

    <properties>
        <java.version>1.8</java.version>
        <spring.version>4.3.9.RELEASE</spring.version>
        <spring.boot.version>1.4.3.RELEASE</spring.boot.version>
        <db2.driver.version>10.5.9</db2.driver.version>
        <spring.batch.version>3.0.8.RELEASE</spring.batch.version>
        <thymeleaf.version>2.1.5.RELEASE</thymeleaf.version>
        <tomcat.version>8.5.6</tomcat.version>
        <poi.version>3.15</poi.version>
        <jackson.version>1.9.10</jackson.version>
    </properties>

    <dependencies>
        <!-- spring dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-logging -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-tx -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- Spring Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-test-autoconfigure -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test-autoconfigure</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-tomcat -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <version>${spring.boot.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring4</artifactId>
            <version>${thymeleaf.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>${thymeleaf.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>

        <!-- Spring Batch dependencies -->
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>${spring.batch.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-infrastructure</artifactId>
            <version>${spring.batch.version}</version><!--$NO-MVN-MAN-VER$ -->
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-test</artifactId>
            <version>${spring.batch.version}</version><!--$NO-MVN-MAN-VER$ -->
            <scope>test</scope>
        </dependency>

我的application.properties:

spring.http.multipart.max-file-size=200MB
spring.http.multipart.max-request-size=1000MB

spring.thymeleaf.mode=LEGACYHTML5 spring.thymeleaf.cache=false

spring.datasource.initialization-mode=never
spring.jpa.hibernate.ddl-auto= none

spring.datasource.url=jdbc:db2://localhost:50000/bluecost
spring.datasource.username=db2admin
spring.datasource.password=db2admin
spring.datasource.driver-class-name=com.ibm.db2.jcc.DB2Driver

所有单元测试用例都使用与数据库的JDBC连接,这需要启动并运行dB(使用正确的模式)以使测试用例正常工作,这很痛苦。我们如何将测试上下文的实现交换到另一种类型的数据库 - 比如HSQLDB?

我在文档中读到S-boot可以自动配置HSQLDB,我们所要做的就是将其指定为依赖项,但是如何让它在运行时使用HSQLDB运行单元测试用例适用于DB2的应用程序?!

更新:我已经向pom.xml添加了hsqldb依赖项,重新启动了应用程序,但它没有看到任何差异......

1 个答案:

答案 0 :(得分:0)

我通过阅读文档找到了自己的答案。