Я пытаюсь настроить фабрику бобов весной, что-то, что должно быть очень просто сделать, но я просто не могу понять, почему это не работает.Проводите большую часть сегодняшнего дня, рассматривая примеры, читая другие подобные посты в stackOverflow, читая Spring In Action, а также Spring Recipes, но пока безуспешно.Вторая пара глаз, вероятно, сразу поймет мою ошибку.
Интерфейс уведомителя об ошибках
public interface ErrorNotifier {
public void notifyCopyError(String srcDir, String destDir, String filename);
}
Реализация уведомителя об ошибке
public class EmailErrorNotifier implements ErrorNotifier {
private MailSender mailSender;
/**
* Blank constructor
*/
public EmailErrorNotifier() {
}
public void setMailSender(MailSender mailSender) {
this.mailSender = mailSender;
}
@Override
public void notifyCopyError(String srcDir, String destDir, String filename) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("system@localhost");
message.setTo("admin@localhost");
message.setSubject("Finished Uploading File");
message.setText("Your upload failed!");
mailSender.send(message);
}
}
Моя конфигурация в applicationContext.xml
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${email.host}"/>
<property name="protocol" value="${email.protocol}"/>
<property name="port" value="${email.port}"/>
<property name="username" value="${email.username}"/>
<property name="password" value="${email.password}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<bean id="errorNotifier" name="errorNotifier" class="com.bdw.controller.EmailErrorNotifier">
<property name="mailSender" ref="mailSender"/>
</bean>
И класс, в котором я его тестирую
public class test {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext(
ApplicationContext.CLASSPATH_ALL_URL_PREFIX
+ "applicationContext.xml");
ErrorNotifier notifier =
context.getBean("errorNotifier", ErrorNotifier.class);
notifier.notifyCopyError("test", "test", "test");
}
}
Я не получаю никаких ошибок в журналах tomcat или glassfish, только этот вывод:
Исключение в потоке "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: для org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanFisory.eBeanFisory.jeBeanDefinitionBeanFisoryBeanDefinition.js не указывается..springframework..AbstractBeanFactory.getBean (AbstractBeanFactory.java:194) в org.springframework.context.support.AbstractApplicationContext.getBean (AbstractApplicationContext.java:1079) в test.main (test.java:21)
Если я изменю параметр context.getBean на поиск mailSender, я не получу bean-компонент с именем «mailSender».
Есть идеи?