What´s the difference between mvn spring-boot:run and “run” in IntelliJ

Viewed 705

I know it may sound like a silly question but I am unable to understand the difference between mvn spring-boot:run and "run" in IntelliJ. The background of my question is that I have a spring boot project that uses JavaMailSender to send a pdf-File via E-Mail.

The project contains two application.properties-files:

src/main/
    +- java
    +- resources
        +- db
        +- template
        +- application.properties
    +- target
    application.properties
    pom.xml

The properties of this JavaMailSender (host, port, username, password) are specified in the second application properties.

@Service
public class PdfService {

private final Logger logger = LoggerFactory.getLogger(PdfService.class);

private PdfCreator pdfCreator;

private ConfigProperties properties;

private JavaMailSender javaMailSender;

private MessageSourceAccessor messageSourceAccessor;

@Autowired
public PdfService(PdfCreator pdfCreator,
                  ConfigProperties properties,
                  JavaMailSender javaMailSender,
                  MessageSourceAccessor messageSourceAccessor) {
    this.pdfCreator = pdfCreator;
    this.properties = properties;
    this.javaMailSender = javaMailSender;
    this.messageSourceAccessor = messageSourceAccessor;
} 

When I start the project using mvn spring-boot:run in the terminal it runs like a charm. When I try to start it in IntelliJ, the IDE can´t create a bean of JavaMailSender. I get this error:

Parameter 3 of constructor in com.example.project.services.PdfService required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.

In the GUI of IntelliJ I can see that the second application.properties-file (which contains the properties needed by JavaMailSender) is grayed out so I assume that the second file is not recognized.

I´d like to understand why the file is not taken into account when the project is build and how I can fix this without writing the properties in my config-file. As the project can be started without any issues using mvn spring-boot:run there I assume that I only have to find run-configurations in IntelliJ.

I am very happy about any kind of explanation and help.enter image description here

0 Answers
Related