【问题标题】:How to remove/hide Atomikos startup error message?如何删除/隐藏 Atomikos 启动错误消息?
【发布时间】:2011-03-02 07:15:08
【问题描述】:

当通过 Spring 配置 Atomikos 时,不需要 jta.properties 或 transactions.properties 文件。尽管如此,Atomikos 还是从打印到 stderr 的以下消息开始:

No properties path set - looking for transactions.properties in classpath...
transactions.properties not found - looking for jta.properties in classpath...
Failed to open transactions properties file - using default values

它看起来好像没有使用 Spring 配置——尽管显然一切都很好。有谁知道如何摆脱这个,所以我最终不会被问 1000 次?

有没有办法从特定组件或 jar 重定向 stderr?

【问题讨论】:

    标签: spring stderr atomikos


    【解决方案1】:

    Atomikos 使用 SLF4J 记录日志。如果仅使用 SLF4J 记录此依赖项,则可以使用 SLF4J 的 NOP binder,不会记录任何内容。可能不是你想要的,但很简单。

    您可以配置 SLF4J 的后端记录器以忽略特定包中的日志消息。 以 logback 作为 SLF4J' 后端记录器的示例:

    <logger name="com.atomikos.something" level="OFF"/>
    

    我写了一篇关于 SLF4J 和不同后端记录器的教程here

    【讨论】:

    • 不幸的是,Atomikos 没有登录到控制台,而是打印到 stderr。在我看来,这是一个错误,但与此同时,我需要摆脱它!谢谢。
    • 你在使用 SLF4J 的 SIMPLE 实现吗?来自Javadoc:一个简单(直接)的实现,在控制台(System.err)上记录级别为 INFO 或更高级别的消息。
    【解决方案2】:

    您需要将系统属性com.atomikos.icatch.hide_init_file_path 设置为任意值。在 java 命令行上执行此操作。在 Maven 中,您可以通过将命令行 arg 传递给 surefire 来执行此操作,如下所示:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <argLine>-Dcom.atomikos.icatch.hide_init_file_path=true</argLine>
        </configuration>
    </plugin>
    

    更新:在 Spring 配置文件中,您可以像这样设置属性:

    <bean id="atomikosSystemProps" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject">
            <!-- System.getProperties() -->
            <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
                <property name="targetClass" value="java.lang.System" />
                <property name="targetMethod" value="getProperties" />
            </bean>
        </property>
        <property name="targetMethod" value="putAll" />
        <property name="arguments">
            <!-- The new Properties -->
            <util:properties>
                <prop key="com.atomikos.icatch.hide_init_file_path">true</prop>
            </util:properties>
        </property>
    </bean>
    

    只要记住让你的 Atomikos bean “依赖”这个 bean,这样实例化的顺序就正确了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      相关资源
      最近更新 更多