Hello, my application.properties code (of course I will change some data):
spring.mail.host=testmail.ovh
spring.mail.port=587
spring.mail.username=test@test.ovh
spring.mail.password=test
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.datasource.url=jdbc:mariadb://localhost:3306/test
spring.datasource.password=test
spring.datasource.username=test
server.port=3000
build.gradle:
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.1'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'pl.test'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
compileJava.options.encoding = 'UTF-8'
dependencies {
implementation 'commons-codec:commons-codec:1.15'
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.2'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.jetbrains:annotations:23.0.0'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.mindrot:jbcrypt:0.4'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
error:
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'mailSender', defined in class path resource [org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.class], could not be registered. A bean with that name has already been defined in file [C:\Users\user\Desktop\minecraftreward\api\build\classes\java\main\pl\test\api\mail\MailSender.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
Comment From: scottfrederick
The Spring Boot class named in that error (org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.class) creates a bean named mailSender of type JavaMailSenderImpl, if a bean of type JavaMailSender is not already present in the app context.
It appears that a class named pl.test.api.mail.MailSender in your application is also creating a bean named mailSender, likely of a different type so the @ConditionalOnMissingBean in Spring Boot isn't backing off. By default, Spring Boot won't allow the creation of one bean to be overridden by the creation of another bean with the same name, so you're getting the error.
It's hard to know exactly what should be happening without seeing the rest of your application. If you think Spring Boot should be behaving differently and you'd like us to take a look, please provide a complete minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.
Comment From: AdamGrabowiecki
Okey, thanks