gpt4 book ai didi

java - 导入org.springframework.mail无法解析

转载 作者:行者123 更新时间:2023-12-01 16:56:46 24 4
gpt4 key购买 nike

我尝试在 Spring Boot 中发送电子邮件,但是导入语句总是显示无法解析。 尝试浏览文章和博客,但它们的重要性与我完全相同,但对我来说仍然不起作用。我根本无法弄清楚我的代码或依赖项 [pom.xml 文件]

有什么问题

当我尝试编写这段代码时

@Autowired
private JavaMailSender mailSender;

导入对此不可用。

当我编写这段代码时

import org.springframework.mail.SimpleMailMessage;

这表示无法解析导入org.springframework.mail。

我的 pom.xml 看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.hamro.app</groupId>
<artifactId>hamro-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hamro-app</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>9.0.20</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>

</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

这有什么问题吗?

最佳答案

您可以尝试更改 spring boot 版本吗?例如,尝试将其设置为 2.1.3.RELEASE(我已经给出了版本,JavaMailSender 工作得很好),然后再次检查。

关于java - 导入org.springframework.mail无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61576607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com