@Component
public class EmailService {
public void sendEmail(String message) {
System.out.println("Sending email: " + message);
}
}
@Component
public class NotificationService {
@Autowired
private EmailService emailService;
public void sendNotification(String message) {
emailService.sendEmail(message);
}
}
public class Main {
public static void main(String[] args) {
NotificationService notificationService = BeanInject.getBean(NotificationService.class);
notificationService.sendNotification("Hello, world!");
}
}
@Configuration
public class AppConfig {
@Bean
public BeanInject beanInject() {
return new BeanInject();
}
}
@Configuration
@ComponentScan(basePackages = "com.example")
public class AppConfig {
@Bean
public BeanInject beanInject() {
return new BeanInject();
}
}