spring不使用多个属性文件

时间:2016-10-15 06:02:55

标签: java spring hibernate

这个问题可能听起来很旧,但我无法使用多个properties文件,因为在寻找解决方案之后我才知道,对于验证员类我添加了hibernate validator 4,5,Jboss Logging final jars现在它的说法

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1197783': Cannot resolve reference to bean 'validator' while setting bean property 'validator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validator' defined in ServletContext resource [/WEB-INF/springDispatcherServlet-servlet.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.hibernate.validator.internal.engine.ConfigurationImpl.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider;

这是我的configuration file

<mvc:annotation-driven enable-matrix-variables="true"
        validator="validator" />
<context:component-scan base-package="com.*" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/views/" />
        <property name="suffix" value=".jsp" />
    </bean>
<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**" />
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="language" />
            </bean>
        </mvc:interceptor>
    </mvc:interceptors>
    <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        value="/com/resources/messages,/com/resources/messages_validation.properties"
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    </bean>

    <bean id="validator"
        class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
        <property name="validationMessageSource" ref="messageSource" />
    </bean>

属性文件的名称(它们位于同一文件夹中)

messages_en.properties
messages_nl.properties
messages_validations.properties

如果一切都在正确的地方,我无法理解为什么它会给我错误

请帮忙

2 个答案:

答案 0 :(得分:0)

尝试,

Just LT

答案 1 :(得分:0)

我想假设你的messageproperties在/ com / resources

下,这应该可行
<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:/com/resources/messages/" />
    <property name="defaultEncoding" value="UTF-8" />
    <property name="fallbackToSystemLocale" value="false"/>
</bean>