天天看点

springboot使用maven父子结构,子模块修改thymeleaf默认版本无效问题,修改其他jar包默认方式在springboot使用maven父子结构,子模块修改thymeleaf默认版本无效问题,修改其他jar包默认方式以上为自己开发过程中遇到的问题,特此记录,如有改进之处,大家指点。

在springboot使用maven父子结构,子模块修改thymeleaf默认版本无效问题,修改其他jar包默认方式

在springboot web开发中,引入thymeleaf的starter后,用如下方式修改jar包默认版本

<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
		<!-- 布局功能的支持程序  thymeleaf3主程序  layout2以上版本 -->
		<!-- thymeleaf2   layout1-->
		<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
	</properties>
           

但是由于使用springboot初始化向导建的工程,都会以spring-boot-starter-parent为父模块

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

如果是这样的话,默认jar包的版本就会被修改

但是在自己开发的时候,我们可能并不会以spring-boot-starter-parent为父模块,我们自己定义父模块,但是我们如果还想像以spring-boot-starter-parent为父模块来管理jar包版本的话,我们在父工程用以下方式来引入依赖

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.5.10.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
           

以上就可以像之前一样管理版本,但是就不能使用properties标签来修改默认jar包版本了,这样可以采用如下方式修改默认jar包版本

<dependencyManagement>
        <dependencies>
            <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 -->
            <dependency>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf-spring4</artifactId>
                <version>3.0.11.RELEASE</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/nz.net.ultraq.thymeleaf/thymeleaf-layout-dialect -->
            <dependency>
                <groupId>nz.net.ultraq.thymeleaf</groupId>
                <artifactId>thymeleaf-layout-dialect</artifactId>
                <version>2.3.0</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
            <dependency>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf</artifactId>
                <version>3.0.11.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.5.10.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
           

我们只要在这里指定我们需要的jar包版本即可。

以上为自己开发过程中遇到的问题,特此记录,如有改进之处,大家指点。

继续阅读