Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
messageSource未由spring自动连接_Spring - Fatal编程技术网

messageSource未由spring自动连接

messageSource未由spring自动连接,spring,Spring,我正在尝试从邮件属性文件中获取邮件 <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>mymessage</value> </list> </property> </bean>

我正在尝试从邮件属性文件中获取邮件

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>mymessage</value>
</list>
</property>
</bean>

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;

public class Test{

@Autowired
    private MessageSource messageSource;
    public MessageSource getMessageSource() {
        return messageSource;
    }
    public void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

public void draw()
    {

    System.out.println(this.messageSource.getMessage("name",null,"default",null));`enter code here`
    }}

我的消息
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.context.MessageSource;
公开课考试{
@自动连线
私有消息源;
public MessageSource getMessageSource(){
返回消息源;
}
public void setMessageSource(MessageSource MessageSource){
this.messageSource=messageSource;
}
公众抽签()
{
System.out.println(this.messageSource.getMessage(“name”,null,“default”,null));`在这里输入代码`
}}
因为我得到了空指针异常


但是,当我更改代码并在测试类中实现MessageSourceAware时,它就可以正常工作了。甚至在我删除@autowired注释和bean id定义本身之后

这里是我在dispatcher上下文“servlet context.xml”中的声明:


将类名从
class=“org.springframework.context.support.ResourceBundleMessageSource
更改为
class=“org.springframework.context.support.ReloadableResourceBundleMessageSource


为什么basename属性为空?

但始终为默认值
<beans:bean id="messageSource"  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <beans:property name="basename" value="classpath:messages" />
    <beans:property name="defaultEncoding" value="UTF-8"/>
    <beans:property name="fileEncodings" value="UTF-8"/>
</beans:bean>