[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

autowiring and spring bean config file?

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
dkim18
Asked:
dkim18
  • 2
2 Solutions
 
chaitu chaituCommented:
xxx.serivce.EmployerServiceImpl

it should be

xxx.service.EmployerServiceImpl
0
 
dkim18Author Commented:
That is just a typing error here.
I have it correctlt.
So you dont see anything wrong right?
0
 
Amitkumar PSr. ConsultantCommented:
yes, chaituu is correct.
0
 
dkim18Author Commented:
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

Independent Software Vendors: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now