Solved

autowiring and spring bean config file?

Posted on 2013-10-25
4
388 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
  • 2
4 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 475 total points
Comment Utility
xxx.serivce.EmployerServiceImpl

it should be

xxx.service.EmployerServiceImpl
0
 

Author Comment

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

Assisted Solution

by:Amitkumar Panchal
Amitkumar Panchal earned 25 total points
Comment Utility
yes, chaituu is correct.
0
 

Author Comment

by:dkim18
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mapBully challenge 6 88
Printing to a specific printer tray (HP 806dn printer) 3 62
python question 5 57
solarwind tftp server 2 30
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.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now