我已经开发了一个 Spring Web 应用程序并且它工作正常。我的 bean 创建映射结构如下:我的控制器:
@Controller
@RequestMapping("appointmentDiary")
public class AppointmentDiaryController {
private IAppointmentDiaryService appointmentDiaryService;
public IAppointmentDiaryService getAppointmentDiaryService() {
return appointmentDiaryService;
}
public void setAppointmentDiaryService(IAppointmentDiaryService appointmentDiaryService) {
this.appointmentDiaryService = appointmentDiaryService;
}
}
My Service Interface:
public interface IAppointmentDiaryService
{
public Integer getAppointmentDiaryNo();
}
My Impl Class:
public class AppointmentDiaryServiceImpl implements IAppointmentDiaryService{
private IAppointmentDiaryDAO appointmentDiaryDAO;
public IAppointmentDiaryDAO getAppointmentDiaryDAO(){
return appointmentDiaryDAO;
}
public void setAppointmentDiaryDAO(IAppointmentDiaryDAO appointmentDiaryDAO) {
this.appointmentDiaryDAO = appointmentDiaryDAO;
}
public Integer getAppointmentDiaryNo(){
InternalResultsResponse<Object> objResponse = getAppointmentDiaryDAO().getAppointmentDiaryNo();
return objResponse;
}
My DAO Interface:
public interface IAppointmentDiaryDAO extends IGenericDAO
{
public InternalResultsResponse<Object> getAppointmentDiaryNo();
}
My DAO Impl calss:
public class AppointmentDiaryDAOImpl extends GenericDAOImpl implements
IAppointmentDiaryDAO {
public InternalResultsResponse<Object> getAppointmentDiaryNo() {
InternalResultsResponse<Object> response = new InternalResultsResponse<Object>();
String sql = SqlProperties.getSQLStatement("getAppointmentDiaryNo");
Session session = getSession();
Transaction tr = session.beginTransaction();
response = HibernateUtil.executeSQLQuery(session, sql);
tr.commit();
return response;
}
}
现在,我不想使用这种结构,我想创建一个包含所有服务接口、Impl 类、DAO 接口和 Impl 类的 jar 文件,这意味着除了控制器之外的所有内容都应该在 jar 文件中。但是当我创建一个 jar 文件并添加项目的类路径并运行项目时发生异常:异常是:
org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [com.nmmc.cess.service.impl.AppointmentDiaryServiceImpl] for bean with name 'appointmentDiaryServiceImpl' defined in ServletContext resource [/WEB-INF/config/cess-service-application-context.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: com/nmmc/cess/service/IAppointmentDiaryService
那么,我该如何配置它将映射 Spring 在 xml 文件中定义的 bean。当我在不使用该 jar 文件的情况下运行项目时,我的 bean 配置工作正常。请给出解决方案。提前致谢。