Want to implement simple mail sender solution based on spring-boot-starter-mail
After adding dependency and set up properties I tried to run app and that error occurred.
I think that's worth noticing that I am not, and not about either to implement Spring Cloud. Just the mail service.
Doesn't understand why spring boot expects some services that are from these package.
Tried various version of dependency, defining some #Beans but don't think that's the issue
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
logs:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-23 00:07:05.752 ERROR 19576 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method mailNotifier in de.codecentric.boot.admin.server.config.AdminServerNotifierAutoConfiguration$MailNotifierConfiguration required a bean of type 'de.codecentric.boot.admin.server.domain.entities.InstanceRepository' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'instanceRepository' in 'AdminServerAutoConfiguration' not loaded because #ConditionalOnBean (types: de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration$Marker; SearchStrategy: all) did not find any beans of type de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration$Marker
Action:
Consider revisiting the entries above or defining a bean of type 'de.codecentric.boot.admin.server.domain.entities.InstanceRepository' in your configuration.
Just want to send email via smtp.gmail.com
Hope that spring-boot-starter-mail 'd be enough for that.
Thanks!
As LHCHIN commented, it was a matter of spring-boot-admin-starter-server and spring-boot-admin-dependencies in <dependencyManagement/>
I would always advice to avoid copy pasting the dependencies with their version. Most of the cases you don't need to specifiy the version and let Spring boot figure out based on mvn which version will be suitable for you.
For the spring boot starter mail, I just needed the following dependencies
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.5.6</version>
</dependency>
The source I used is : https://www.baeldung.com/spring-email and it worked for me with version and without.
Related
I'm following a tutorial on Java Spring Boot and the current topic is that one can use both application.properties and application.yml
So my application.properties looked like this:
spring.profiles.active=EN, cat
custom.username=user
custom.password=pass
I deleted it and created an application.yml instead. IntelliJ even marks it with the little green start button icon. application.yml looks like this:
spring:
profiles:
active: EN, cat
custom:
username: user
password: pass
But when I do the custom properties don't get recognized any more. The IDE marks them red and shows this error: "Key 'custom' is not expected here"
I wasn't sure if that's correct so I tried what the IDE suggested when using autocomplete to write spring.profiles.active which was writing the list elements like this:
spring:
profiles:
active:
- EN
- cat
custom:
username: user
password: pass
But that also didn't help.
I'm not sure where to go from here. I've tried to research the issue, however the only hits I get that come somewhat close all just mention that it's possible to use yml instead of properties and some even use custom properties like I displayed above.
Is this maybe a version issue? My pom looks like this:
<?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.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>myID</groupId>
<artifactId>myArtifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>myName</name>
<description>myDescription</description>
<properties>
<java.version>11</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Update
To answer the question Mark B posed in the comments. This is the error message:
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-01-05T08:58:07.711+01:00 ERROR 5026 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in my.package.controllers.I18nController required a bean of type 'my.package.services.GreetingService' that could not be found.
The injection point has the following annotations:
- #org.springframework.beans.factory.annotation.Qualifier("i18nService")
The following candidates were found but could not be injected:
- User-defined bean
- User-defined bean
- User-defined bean method 'primaryGreetingService' in 'GreetingServiceConfig'
- User-defined bean method 'propertyInjectedGreetingService' in 'GreetingServiceConfig'
- User-defined bean method 'setterInjectedGreetingService' in 'GreetingServiceConfig'
- User-defined bean
Action:
Consider revisiting the entries above or defining a bean of type 'my.package.services.GreetingService' in your configuration.
Process finished with exit code 1
At first glance this looks like maybe I messed up something within the definition or configuration of my beans. However, when I revert my repository back to the state where I used the application.properties file as described above, everything works as expected.
I retook the steps to isolate the problem as much as possible.
All I did was:
delete application.properties
create application.yml
I have changed nothing else.
git status (translated and simplified):
On Branch master
Your Branch is in the same state as 'origin/master'.
Staged changes:
deleted: src/main/resources/application.properties
new file: src/main/resources/application.yml
Unstaged changes::
changed: src/main/resources/application.yml
src/main/resources/application.yml is staged as new file and then has unstaged changes because the IDE staged the new file on creation. Just to clear out any confusion. Though this shouldn't affect the outcome.
Update 2
As suggested in the comments I tried to add #ConfigurationProperties(prefix = "custom"), but all that did was change the error slightly:
Error creating bean with name 'i18nController' defined in file
[/path/target/classes/my/package/controllers/I18nController.class]:
Unsatisfied dependency expressed through constructor parameter 0:
No qualifying bean of type 'my.package.services.GreetingService' available:
expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations:
{#org.springframework.beans.factory.annotation.Qualifier("i18nService")}
As you're using spring-boot-starter SnakeYAML library should be on your classpath, but please double-check with mvn dependency:list, search the output for a line [INFO] org.yaml:snakeyaml:jar:1.33:compile -- module org.yaml.snakeyaml [auto] .
If it's missing, then please add SnakeYAML dependency: https://mvnrepository.com/artifact/org.yaml/snakeyaml
Eclipse IDE has auto-convertion mechanism which converts properties into yaml format. Just right click on the file and click "convert" it works like a charm. I'm using Eclipse STS edition.
I guess that you're not sharing full properties file and there is a syntax error or something is missing in your yaml configuration. Please give a try with plugins which are available for InteliJ IDEA: https://plugins.jetbrains.com/plugin/8000-properties-to-yaml-converter or online converters like: https://www.javainuse.com/app2yaml .
UPDATE:
I Decided to reproduce your example code on my machine with exactly the same version of SpringBoot and Java. First of all I've created a properties files and tested (it worked fine) and then migrated properties file into YAML format and it also works fine with exactly the same result.
When it comes to unexpected key custom it only says that this key if unknown (more like warning then error), and you can define it in META-INF like below.
So as other comments suggest I'm sure that it's connected to code which relays on properties file in some hardcoded way (for example #PropertySource annotation, see also my comment below).
I´m working on this Vaadin Tutorial series.
https://www.youtube.com/watch?v=k-DxZ1reIdM&list=PLcRrh9hGNallPtT2VbUAsrWqvkQ-XE22h&index=11
Text Version: https://vaadin.com/learn/tutorials/modern-web-apps-with-spring-boot-and-vaadin/vaadin-form-data-binding-and-validation?
I´m trying to use Binding but I get the following error in my Terminal:
2020-11-22 09:11:11.012 INFO 38103 --- [nio-8080-exec-2] c.vaadin.flow.spring.SpringInstantiator : The number of beans implementing 'I18NProvider' is 0. Cannot use Spring beans for I18N, falling back to the default behavior
2020-11-22 09:11:11.373 INFO 38103 --- [nio-8080-exec-2] com.vaadin.validator.BeanValidator : A JSR-303 bean validation implementation not found on the classpath or could not be initialized. BeanValidator cannot be used.
more below the next:
Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
How do I add a Bean Validation provider? I´m working with vaadin as a maven project same as in the tutorial.
Solved by adding the following dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
So I have this springboot application which I'm migrating from a WAS to a springboot setup. And I have a couple of JSPs which has to be configured. To accomodate these I added the following dependencies:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
The application already came with the following dependency which is being used throughout the application:
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm-jaxrpc-client</artifactId>
<version>6.0</version>
</dependency>
The issue I'm facing is that both these dependencies (jaxrpc-client and tomcat-embed-jasper) have javax.servlet.ServletContext classes in them which is causing the following error:
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/C:/Users/.m2/repository/com/ibm/com.ibm-jaxrpc-client/6.0/com.ibm-jaxrpc-client-6.0.jar!/javax/servlet/ServletContext.class
jar:file:/C:/Users/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.30/tomcat-embed-core-9.0.30.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/C:/Users/.m2/repository/com/ibm/com.ibm-jaxrpc-client/6.0/com.ibm-jaxrpc-client-6.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
I can't afford to remove any of these dependencies. jaxrpc-client is being referenced in the code already in too many places and I need tomcat-embed-jasper to render my jsp pages. I can't exclude the ServletContext class since its not a dependency(If I'm not wrong about the concept of exclusion). Please help with with a way forward with this issue.
I'm not familiar with IBM's jaxrpc client, but I assume, you have this exception in runtime, when trying to load the application.
In this case consider the following approaches:
Use another jax-rpc client library
Consider Loading the code that uses this library with the different class-loader (you'll have to create one classloader for this) to avoid the clash
Kind of paraphrasing the second option. You can "play" (override the order of loading of specific classes) with spring boot classloader as described in this article
I know, this is too general answer, but hopefully its still helpful.
The first solution is by far the easiest way I can think of.
The second solution is doable, however it pretty much depends on how exactly the code that uses the jax rpc client is loaded and used.
I had swagger_jaxrs_2.10 (1.3.6) working for a long time, I want to benefit from the new 2.0 swagger specification.
Hence I've changed in my pom from
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.6</version>
</dependency>
to
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.3</version>
</dependency>
When I run, I get the following error trying to access myApp/swagger.json
SEVERE: Conflicting URI templates. The URI template / for root resource class io.swagger.jaxrs.listing.ApiListingResource and the URI template / transform to the same regular expression (/.*)?
Any ideas?
In the case of swagger from the 1.5.x libraries, the swagger description will live at /swagger.json. It depends on where your app is mounted though.
The error message your describing tells me that you're mounting a root resource (/*) which is indeed going to conflict with the /swagger.json. Consider mounting your API on a path like /users or something else to avoid that conflict.
I've been going through the process of converting my Mule project to a Spring Boot application, and have hit a snag I can't seem to figure out.
I'm pretty new to Spring Boot so I'm not sure if my issues lie with it, or with the way I'm doing my mule stuff.
Here is my sample project I've been trying to convert: https://github.com/JustinBell/mule-webapp-example
When I deploy this to a tomcat instance it works great, the issue comes when I try to run it as a Spring Boot application I'm getting this exception:
ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
Just as a note I'm moving from mule 3.6.1 to 3.7.0-M1 as that's required (from my understanding) to use Spring Boot.
I've tried looking around for support on this issue which seems to pretty common, but none of the suggestions I've found have solved the issue.
Thanks for any help with these issues!
There are a few things that aren't quite right in your code as it stands.
If you want to build a web app with Spring Boot, you'll typically want to add a dependency on spring-boot-starter-web. This provides, among other things, the embedded servlet container:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>
Your app's dependency on org.mule.transports:mule-transport-servlet pulls in a very old version of Tomcat's Coyote module. You need to exclude this to avoid it clashing with the up-to-date dependency that's provided by spring-boot-starter-web:
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-servlet</artifactId>
<version>${mule.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>coyote</artifactId>
</exclusion>
</exclusions>
</dependency>
Your Application class is trying to run MuleContextInitializer which it also declares as a bean. It should be running Application.class:
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class);
}
// ...
}
Your Application class is also in the default package. You should avoid using the default package as it will cause Spring Boot to scan then entire classpath looking for your application's classes and configuration. Moving it into a package of its own to stop this from happening.
Lastly, the app fails to launch as it's looking for a file named mule-config.xml. Renaming mule-webapp-demo.xml to mule-config.xml addresses this.
I believe autodelete is an Enterprise feature, perhaps you are using ftp rather than ftp-ee.