我爱编程

项目配置管理

2018-04-11  本文已影响29人  xuefly

要完成的目标

放置mapper.xml

参考:mybatis错误——java.io.IOException: Could not find resource com/xxx/xxxMapper.xml - CSDN博客
直接放在src/java/main下没有成功,最终放在:src\main\resources\mapper

<mappers>
        <mapper resource="mapper/GroupMapper.xml" />
        <mapper resource="mapper/GroupRoleMapper.xml" />
        <mapper resource="mapper/PrivHiveHdfsMapper.xml" />
        <mapper resource="mapper/RoleMapper.xml" />
        <mapper resource="mapper/RolePrivMapper.xml" />
        <mapper resource="mapper/UserGroupMapper.xml" />
        <mapper resource="mapper/UserMapper.xml" />
        <mapper resource="mapper/UserRoleMapper.xml" />
    </mappers>

修改pom.xml

作为项目配置环境的总入口,通过maven的profile机制来切换环境。

 <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/resources/${profiles.activation}/</directory>
            </resource>
        </resources>

在project标签内:

 <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profiles.activation>dev</profiles.activation>
            </properties>
        </profile>

        <profile>
            <id>pro</id>
            <properties>
                <profiles.activation>pro</profiles.activation>
            </properties>
        </profile>
    </profiles>

springboot的配置环境切换

修改中:application.properties
spring.profiles.active=@profiles.activation@

这样:
application.properties中应用maven的pom.xml中引用profiles.activation.

注意:一般${}方式会被maven处理。如果你pom继承了spring-boot-starter-parent,Spring
Boot已经将maven-resources-plugins默认的${}方式改为了@@方式,如@name@

最终效果

项目的resource目录


image.png

`mvn package'后,检查项目的target目录:除了kdbs项目下的代码,其他都是在resource目录下的内容。


image.png
上一篇 下一篇

猜你喜欢

热点阅读