我刚刚将我的项目从 Windows 转移到 Ubuntu。在 Windows 上程序运行良好,但在 Ubuntu 中出现此错误:
Bean of type Org.springframework.mail.javamail.JavaMailSender could not be found
下面是代码以及我是如何使用它的。它在 Windows 上运行,不使用 Ubuntu 并出现此错误
@Autowired
private JavaMailSender mailSender;
User user = userService.findByUsername(principal.getName());
Order order = orderService.createOrder(shoppingCart, shippingAddress, billingAddress, payment, shippingMethod, user);
mailSender.send(mailConstructor.constructOrderConfirmationEmail(user, order, Locale.ENGLISH));
shoppingCartService.clearShoppingCart(shoppingCart);
LocalDate today = LocalDate.now();
LocalDate estimatedDeliveryDate;
***************************
APPLICATION FAILED TO START
***************************
Description:
Field mailSender in com.bookstore.controller.CheckoutController required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
- Bean method 'mailSender' not loaded because AnyNestedCondition 0 matched 2 did not; NestedCondition on MailSenderAutoConfiguration.MailSenderCondition.JndiNameProperty @ConditionalOnProperty (spring.mail.jndi-name) did not find property 'jndi-name'; NestedCondition on MailSenderAutoConfiguration.MailSenderCondition.HostProperty @ConditionalOnProperty (spring.mail.host) did not find property 'host'
Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.mail.javamail.JavaMailSender' in your configuration.
我认为这与防病毒有关,在 Windows 中我不得不禁用防病毒,但在 Ubuntu 中我该怎么办?
最佳答案
您是否已迁移您的 application.properties?
由于@ConditionalOnProperty 注解,bean 未加载。它期望首先初始化其他 beans/prorties,这由 application.properties 中的值控制
关于java - 找不到类型为 Org.springframework.mail.javamail.JavaMailSender 的 Bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46756217/