1

This is a follow up question for org.xml.sax.SAXParseException;cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found The issue in that question is fixed but i'm now seeing BeanCreationException for stuff that was working before I made the change.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.mail.SimpleMailMessage com.xxx.service.EmployeeService.templateMessage; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.mail.SimpleMailMessage] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 

My REST controller is annotated this way

@RestController public class EmployeeController 

And my service

@Service("employeeService") public class EmployeeService 

2 Answers 2

1

add this/similar in your applicationContext xml file.

<bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="[email protected]" /> <property name="to" value="[email protected]" /> <property name="subject" value="Testing Subject" /> <property name="text"> <value> <![CDATA[ Dear %s, Mail Content : %s ]]> </value> </property> </bean> 
Sign up to request clarification or add additional context in comments.

5 Comments

I did this and I went back to my original problem of stackoverflow.com/questions/42941003/…
you can use javaconfig to get rid of xml issues like this.refer stackoverflow.com/a/24097225/1401019
Is that Javaconfig only applicable for Spring Boot? Also is there a full example I can follow?
It is not specific to Spring boot, you can refer this article for how-to of java config. samerabdelkafi.wordpress.com/2014/08/03/…
1

Have you enabled the component scanning in Spring ?

Also below is an example of how your bean-configuration should be :

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="customerService" class="com.abc.customer.services.CustomerService"> <property name="customerDAO" ref="customerDAO" /> </bean> enter code here <bean id="customerDAO" class="com.abc.customer.dao.CustomerDAO" /> </beans> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.