?
Solved

autowiring and spring bean config file?

Posted on 2013-10-25
4
Medium Priority
?
406 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 1900 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Make the most of your online learning experience.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Progress
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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