Solved

autowiring and spring bean config file?

Posted on 2013-10-25
4
397 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Infrastructure development vs software development 3 81
incorrect syntax near the order by 10 57
batch file or script 4 50
What is the use of Forwarding Class in java 1 37
A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches viewers about errors in exception handling.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

749 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