Spring删除打印输出无法从URL加载属性 [英] Spring remove printout Could not load properties from URL

查看:154
本文介绍了Spring删除打印输出无法从URL加载属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个gradle插件,我希望用户能够从外部文件覆盖某些属性。
我使用Spring propertyPlaceholderConfigurer来设置用户可以放置文件的几个目的地,这可以按预期工作。
我的问题是,当运行我的插件春天打印出来的控制台:无法加载URL的属性[...]
有没有人有任何想法我会怎么去压制这条消息?

I'm building a gradle plugin in which I want to give users the ability to override some properties from an external file. I'm using the Spring propertyPlaceholderConfigurer in order to set a few destinations where users can place their files, This works as expected. My problem is that when running my plugin Spring prints out to the console: "Could not load properties from URL [...]" Does anyone have any idea how I would go about squelching this message?

我试过重写logback和sl4j无济于事。

I've tried overriding logback and sl4j to no avail.

我的Spring应用程序上下文xml:

My Spring application-context xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:security="http://www.springframework.org/schema/security"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"
   default-lazy-init="true">

<!-- Activates scanning of @Autowired -->
<context:annotation-config/>

<!-- Activates scanning of @Repository and @Service -->
<context:component-scan base-package="com.example.test"/>

<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:/conf/plugin.properties</value>
            <value>file:${user.home}/conf/plugin.properties</value>
            <value>file:${user.home}/conf/plugin-override.properties</value>
        </list>
    </property>
    <property name="placeholderPrefix" value="${"/>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="systemPropertiesMode" value="2"/>
</bean>


推荐答案

如果您想实现自定义逻辑来设置位置,可以扩展 PropertyPlaceholderConfigurer 类似于

If you want to implement custom logic to set locations you can extend PropertyPlaceholderConfigurer like

class CustomPropertyPlaceholderConfigurer extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {

    public void setFileName(String fileName) throws FileNotFoundException {
        File file = findPropertyFile(fileName);  // implement property file loading
        super.setLocation(new FileSystemResource(file));
    }

并像使用它一样

<bean id="propertyPlaceholderConfigurer" class="package.CustomPropertyPlaceholderConfigurer ">
    <property name="placeholderPrefix" value="${"/>
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="systemPropertiesMode" value="2"/>
</bean>

这篇关于Spring删除打印输出无法从URL加载属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆