java - 找不到类型为 Org.springframework.mail.javamail.JavaMailSender 的 Bean?

标签 java spring ubuntu spring-boot

我刚刚将我的项目从 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/

相关文章:

Java:无法使用类路径加载包含 jar 文件的主类

java - 调用静态方法时是否需要调用单独的方法?

Java SELECT 查询 您的 SQL 语法有错误

Spring 数据 JPA。如何从 findAll() 方法中仅获取 ID 列表

Java/Spring/JSP - 如何使用 ModelAndView.addObject 输出附加值

ubuntu - 从用户 shell 执行命令的 Ansible 剧本

ruby-on-rails - 如何在安装在 vmware 中的 ubuntu 中运行 ruby​​ on rails 程序?

java - 将图像上传到 Firebase 存储

java - 基于属性 Autowiring bean

python - 带有请求的 flask 损坏的管道