春季:如何使用库配置文件

时间:2018-09-19 06:51:01

标签: spring spring-boot

我在我的项目中使用了这个依赖库:

enter image description here

如您所见,它正在提供一个canigo-core-i18n.xml文件,内容如下:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">

    <bean id="messageSource"
        class="cat.gencat.ctti.canigo.arch.core.i18n.CustomResourceBundleMessageSource">
        <description>
            Message Resource that is responsible for loading and providing internationalization to the framework.

            To retrieve the necessary locale to retrieve the literals:
             - Validate if we find it informed in the thread of the request
             - Validate if you have a default locale, see: defaultLocale
             - Locality of the VM instance 
        </description>
        <property name="basenames">
            <list>
                <value>cat.gencat.ctti.canigo.arch.config.i18n.</value>
                <value>config.i18n.</value>             
            </list>
        </property>
        <property name="defaultLocale" value="${application.defaultLanguage}"/>
    </bean>

</beans>

我需要解决两个问题吗?

<bean id="messageSource">id属性的用途是什么?我如何获得该bean的实例?

当前,我正在使用以下代码来获取I18nResourceBundleMessageSource实例:

@Bean
public I18nResourceBundleMessageSource canigoMessageSource() {
    CustomResourceBundleMessageSource messageSource = new CustomResourceBundleMessageSource();
    messageSource.setBasenames(new String[]{"messages/exceptions/document"});
    messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
    return messageSource;
}

我可以删除此代码吗?

0 个答案:

没有答案