1

我对 Helidon 2.0.1 有疑问

当我尝试使用 ConfigFile 使用外部文件 /etc/config/application.yaml 时,JPA 不起作用。它的端口配置(serve.port:8001)。

好消息是当我使用内部配置文件时,它运行良好,使用“src/main/resources/application.yaml”

我的自定义启动服务器:

    static Server startServer() {
        return Server.builder() 
                .config(buildConfig()) 
                .build() 
                .start();
    }

    public static Config buildConfig() {
        return Config.builder().sources( 
                ConfigSources.file("/etc/conf/application.yaml")
        ).build();
    }

我的persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
    xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                                 http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
    <persistence-unit name="ZettaPU"
        transaction-type="JTA">
        <description>A persistence unit for the Zetta.</description>
        <jta-data-source>ZettaDS</jta-data-source>
        <class>com.zetta.entities.Catalogo</class>
        <properties>
            <property name="eclipselink.deploy-on-startup" value="true" />
            <property name="eclipselink.jdbc.native-sql" value="true" />
            <property name="eclipselink.logging.logger" value="JavaLogger" />
            <property name="eclipselink.logging.parameters" value="true" />
            <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.SQLServerPlatform" />
            <property name="eclipselink.target-server" value="io.helidon.integrations.cdi.eclipselink.CDISEPlatform" />
            <property name="eclipselink.weaving" value="false" />
        </properties>
    </persistence-unit>
</persistence>

我的应用程序.yaml

server:
    port: 8001
    host: 0.0.0.0
javax:
    sql:
        DataSource: 
            distribuidoresDS: 
                dataSourceClassName: com.microsoft.sqlserver.jdbc.SQLServerDataSource
                dataSource: 
                    url: jdbc:sqlserver://localhost:1433;databaseName=ZettaDB; 
                    user: zettaDB
                    password: ********

非常感谢

4

1 回答 1

0

正如https://helidon.io/docs/latest/#/mp/guides/03_config所解释的,我建议您尝试一下这个解决方案:

  private static Config buildConfig() {
    return Config.builder()
        .disableEnvironmentVariablesSource() 
        .sources(
            file("/etc/conf/application.yaml"),
            classpath("application.yaml"), 
            classpath("META-INF/microprofile-config.properties")) 
        .build();
  }

PS:顺序对于让内部配置被外部覆盖很重要。

于 2021-05-19T06:42:35.997 回答