@Configuration
public class Class1 {
@Bean
public JavaMailSenderImpl mailSender() {
....
}
}
@Component
public class Class2 {
@Autowired
JavaMailSenderImpl mailSender;
И я все еще получаю:
No qualifying bean of type [org.springframework.mail.javamail.JavaMailSenderImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Could not autowire field: org.springframework.mail.javamail.JavaMailSenderImpl (path_of_where_autowiring); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.javamail.JavaMailSenderImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Расположение компонента Class1 в Package1
, а расположение Class2 в Package2
.
Почему мой боб не найден? Помощь
(тоже пробовал эту ссылку но мне не помогло)
EDIT
public static void main(String[] args) throws URISyntaxException, IOException {
ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
Implclass nsi = applicationContext.getBean(Implclass.class);
nsi.the_method_here();
}
@Component
public class Implclass implements Implinterface {
@Autowired
JavaMailSenderImpl mailSender;
@Override
public void the_method_here(){
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(sender);
message.setTo(receiver);
message.setSubject(subject);
message.setText(content);
mailSenderService.send(message);
}
}
@Configuration
@ComponentScan
public class SpringConfiguration {
@Bean
public PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertyPlaceholderConfigurer.setLocations(new ClassPathResource("some_property.file"));
propertyPlaceholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
return propertyPlaceholderConfigurer;
}
}
РЕДАКТИРОВАТЬ (ДЕРЕВО)
x - src/main/java
x -- package_1
x - Class1
x -- package_2
x - Class2 (ImplClass)