1. 程式人生 > >SpringBoot異常:IDEA+SpringBoot+Mybatis使用generatorConfig.xml生成xml,Maven打包異常

SpringBoot異常:IDEA+SpringBoot+Mybatis使用generatorConfig.xml生成xml,Maven打包異常

IDEA+SpringBoot+Mybatis專案,使用generatorConfig.xml生成xml

在Maven打包的時候出現異常

在maven package打包時,竟然運行了generatorConfig.xml,把已經修改的java類和xml原件覆蓋掉了,導致問題出現了

解決辦法我是把generatorConfig.xml的table配置改為如下:

<!-- 相關表的配置 -->
<table tableName="****" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample
="false" enableUpdateByExample="false"/>

————————更新——————————

上述方法是錯誤的!!!

打包是成功了,但是執行jar的時候出現問題了。。。。。提示 unable to start.....container

再回到IDEA編譯專案,發現也出現這個問題,代表上面那樣改是不正確的,於是就想不讓mvn package打包的時候執行mybatis-generator外掛,就找到如下方法,最終配置如下:

<build>
   <resources>
      <resource>
         <directory>
src/main/java</directory> <!--配置此項是為了讓maven搬運Java目錄下的xml檔案,預設是不搬運java目錄下的xml檔案--> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <!--讓maven不搬運的檔案和目錄--> <resource>
<directory>src/main/resources</directory> <excludes> <exclude>mybatis/generatorConfig.xml</exclude> <exclude>db/*</exclude> </excludes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <!--配置檔案的位置--> <configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <phase>deploy</phase><!--解決mvn package打包的時候執行了mybatis-generator-maven-plugin導致無法打包問題--> <goals> <goal>generate</goal></goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin> </plugins> </build>