Solved

autowiring and spring bean config file?

Posted on 2013-10-25
4
400 Views
Last Modified: 2013-10-27
Hi,

I am getting the classnotfound error message.
Can you take a look at my code and see if I am setting this up correctly?

0) Error:
Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [xxx.serivce.EmployerServiceImpl] for bean with name 'employerService' defined in class path resource [spring-context.xml]; nested exception is java.lang.ClassNotFoundException: xxxx.serivce.EmployerServiceImpl

Open in new window


1) Dao class
public class EmployeeDaoImpl extends JdbcDaoSupport implements EmployeeDao {
public employee findEmployee(String empID) {
String sql=""; 
return (Employee)getJdbcTemplate().query(sql, new EmployeeRawMapper());
}

}

Open in new window

2) Service class
@Service
public class EmployerServiceImpl implements EmployerService {
@Autowired
private EmployeeDao employeeDao;

public Employee findEmployee(String empID) 
 return employeeDao.findEmployee(empID);

}

Open in new window

3) App.java - main class for testing purpose

public static void main(String[] args) {

		ApplicationContext context = 
	    		new ClassPathXmlApplicationContext("spring-context.xml");
	       // 1) This works fine.
	        EmployeeDao e1 = (EmployeeDao) context.getBean("employeeDao");
	        Employee myEmployee = (Employee)e1.findEmployee("1234");     	      
	        System.out.println("Employee #1  : " + myEmployee.getFullName();
	        
	       //2) This one errors out the above message:
	        EmployerService eService = (EmployerService)context.getBean("employerService");	   
	        
	        Employee myEmployee = (Employee)eService.findEmployee("1234");

Open in new window

4) spring-context.xml
<context:annotation-config />
	<bean
		class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor">
		<property name="requiredParameterValue" value="false" />
	</bean>
<bean id="dataSource" xxxx
</bean>
<bean id="employeeDao" class="xxx.dao.EmployeeDaoImpl">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<bean id="employerService" class="xxx.serivce.EmployerServiceImpl">
	</bean>

Open in new window

0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 475 total points
ID: 39602151
xxx.serivce.EmployerServiceImpl

it should be

xxx.service.EmployerServiceImpl
0
 

Author Comment

by:dkim18
ID: 39602323
That is just a typing error here.
I have it correctlt.
So you dont see anything wrong right?
0
 
LVL 21

Assisted Solution

by:Amitkumar Panchal
Amitkumar Panchal earned 25 total points
ID: 39604062
yes, chaituu is correct.
0
 

Author Comment

by:dkim18
ID: 39604748
chaituu,

you were right.
That's how  I had it in my config file.
I thought I mistyped it when I was input this post.
Thanks.
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question