【问题标题】:How to save the password for a SQL Azure Database in Application Settings in Azure?如何在 Azure 的应用程序设置中保存 SQL Azure 数据库的密码?
【发布时间】:2019-12-10 12:09:25
【问题描述】:

我正在使用适用于 Azure 的 Linux Web 应用程序和 SQL Azure 数据库。

我可以在META-INF/context.xml 中保存我的 SQL Azure 数据库密码(为了论证,我们假设它是pass123),这很成功

<Context>
<Resource name="jdbc/myDB" type="javax.sql.DataSource" auth="Container"
       factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
       driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" initialSize="30"
       maxActive="100" validationQuery="SELECT 1"
       validationQueryTimeout="1000"
       testOnBorrow="true"
       url="jdbc:sqlserver://exampleserver.database.windows.net:1433;database=exampledb;encrypt=true;hostNameInCertificate=westeurope1-a.control.database.windows.net;
       loginTimeout=10;user=myuser;
       password=pass123"
            />
</Context>

但是,我希望密码被加密,而不是以明文形式存储在 context.xml 文件中。所以我做了以下 - 基于https://docs.microsoft.com/en-us/azure/app-service/containers/configure-language-java#data-sources

我添加了两个 Web App/Configuration/Application Settings CATALINA_OPTSTHEDBPASSWORD

我将CATALINA_OPTS 设置为"$CATALINA_OPTS -Ddbpassword={THEDBPASSWORD}"

我将THEDBPASSWORD设置为用户的密码

然后我将context.xml 更改为password={dbpassword} 而不是password=pass123

然后我在日志中收到以下错误(并且应用程序无法启动)

Error: Could not find or load main class "$CATALINA_OPTS -Ddbpassword=pass123" -Ddbpassword=pass123

有什么想法吗?

【问题讨论】:

    标签: azure web-applications


    【解决方案1】:

    我通过以下方式解决了这个问题:

    1. 我忘记了 context.xml 中的 $

    所以context.xml 必须是password=${dbpassword}

    1. 我还将CATALINA_OPTS 更改为-Ddbpassword=pass123

    2. 我放弃了THEDBPASSWORD 变量

    我确信这不是唯一的方法或最好的方法,但至少它有效。 我的部分灵感来自Tomcat 8 - context.xml use Environment Variable in Datasource

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多