无法解析导入的org.springframework.mail

问题描述 投票:0回答:1

我在春季启动时尝试了发送电子邮件,但是import语句总是说无法解决。尝试浏览文章和博客,但它们的导入与我的导入完全相同,但仍然对我不起作用。我根本无法弄清楚我的代码或依赖项 [pom.xml文件]

有什么问题

当我尝试编写此代码时

@Autowired
private JavaMailSender mailSender;

导入对此不可用。

当我编写此代码时

import org.springframework.mail.SimpleMailMessage;

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

我的pom.xml看起来像这样

<?xml version="1.0" encoding="UTF-8"?>

https://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0org.springframework.boot弹簧启动启动器父母2.2.6。发布com.hamro.apphamro-app0.0.1-快照hamro-appSpring Boot的演示项目

<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>

这怎么了?

java spring spring-boot javamail
1个回答
0
投票

您可以尝试更改Spring Boot版本吗?尝试将其设置为2.1.3.RELEASE(我已经给出了版本,JavaMailSender运行得很好),然后再次检查。

© www.soinside.com 2019 - 2024. All rights reserved.