Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义加密字符只能放置在项目下吗,如何做到开发和生产配置文件分离? #2

Open
wulinjie122 opened this issue Aug 21, 2018 · 2 comments

Comments

@wulinjie122
Copy link

方式二:如果项目中不存在以上文件,且不想单独新增,也可以在项目启动时调用 ConfigUtil.bundleNames("xxx") 来指定要读取的文件,这时只会从用户给定的文件中查找。

ConfigUtil.bundleNames只能指定项目路径classpath下的某个属性文件吗?如果我将来要发布到生产环境,怎么读取linux服务器上分离出来的属性文件呢?
或者是否支持spring boot的application.yml文件,在yml文件里配置呢?

@drtrang
Copy link
Owner

drtrang commented Aug 22, 2018

@wulinjie122

spring boot 使用时仅支持 application.properties,不支持 application.yml

其实不同环境的配置可以通过 maven 的 profile 功能来实现。

  1. 在 maven 中新建 dev 和 prod 两个 profile
<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>
</profiles>
  1. 在 src/main/resources/encrypt 下新建 encrypt.propertiesencrypt-dev.propertiesencrypt-prod.properties 三个文件

  2. 在 pom.xml 的 resources 标签下声明 resource 和 filter 即可

<build>
    <resources>
        <resource>
            <directory>src/main/resources/encrypt</directory>
            <filtering>true</filtering>
            <includes>
                <include>encrypt.properties</include>
            </includes>
        </resource>
    </resources>
    <filters>
        <filter>src/main/resources/encrypt/encrypt-${env}.properties</filter>
    </filters>
</build>

@wulinjie122
Copy link
Author

好的,谢谢,我试一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants