Я настраиваю проект Spring MVC с контроллером и службами, когда пытаюсь запустить мой проект на сервере, я получаю исключение следующим образом
org.springframework.beans.factory.UnsatisfiedDependencyException:
Ошибка создания компонента с именем operationDAOImp: неудовлетворенная зависимость
выражается через поле sessionFactory; вложенное исключение
org.springframework.beans.factory.NoSuchBeanDefinitionException: нет
доступен квалифицирующий компонент типа 'org.hibernate.SessionFactory':
ожидается, по крайней мере, 1 боб, который считается кандидатом autowire
Аннотации зависимостей:
{@ Org.springframework.beans.factory.annotation.Autowired (обязательно = истина)}
вот мой контроллер
@RestController
@RequestMapping(value ="/operations")
public class OperationsController {
@Autowired
OperationsServiceInter operService;
private HttpHeaders headers = new HttpHeaders();
Map<String, Object> message = null;
@PostMapping(value = "/scat")
public ResponseEntity<Map<String, Object>> addServiceCategory(@RequestBody ServiceCategory servCat) {
headers = new HttpHeaders();
message = new HashMap<String, Object>();
ResponseEntity<Map<String, Object>> responseEntity = null;
try {
boolean result = operService.addOrUpdateCategory(servCat);
if (result) {
headers.add("head", "addServiceCategory");
message.put("status", true);
message.put("data", "Service category added succesfully");
responseEntity = new ResponseEntity<Map<String, Object>>(message, headers, HttpStatus.OK);
} else {
headers.add("head", "addServiceCategory");
message.put("status", false);
message.put("data", "Service category NOT added");
responseEntity = new ResponseEntity<Map<String, Object>>(message, headers, HttpStatus.OK);
}
} catch (Exception e) {
headers.add("head", "addServiceCategory");
message.put("status", false);
message.put("data", "Exception occured");
responseEntity = new ResponseEntity<Map<String, Object>>(message, headers, HttpStatus.OK);
e.printStackTrace();
}
return responseEntity;
}
}
вот мой сервис Интерфейс и реализации
Интерфейс
пакет com.makingDoctors.service;
import com.makingDoctors.entity.ServiceCategory;
public interface OperationsServiceInter {
boolean addOrUpdateCategory(ServiceCategory servCat);
}
реализация сервиса
@Service
public class OperationsServiceImp implements OperationsServiceInter {
@Autowired
OperationsDAOInter operDao;
/*service category start*/
@Override
@Transactional
public boolean addOrUpdateCategory(ServiceCategory servCat) {
return operDao.addOrUpdateCategory(servCat);
}
/*service category end*/
}
вот моя реализация DAO
@Repository
public class OperationDAOImp implements OperationsDAOInter {
@Autowired
private SessionFactory sessionFactory;
private Session currentSession = null;
private CriteriaBuilder critBuilder;
/*service category start*/
@Override
public boolean addOrUpdateCategory(ServiceCategory servCat) {
boolean success = false;
try {
currentSession = sessionFactory.getCurrentSession();
currentSession.saveOrUpdate(servCat);
success=true;
}
catch (Exception e) {
e.printStackTrace();
success = false;
}
return success;
}
/*service category end*/
}
когда я запускаюсь на сервере, я получаю исключение ниже
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'operationDAOImp': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.hibernate.SessionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1140)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1027)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5038)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5348)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'org.hibernate.SessionFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 31 more
что не так в моей конфигурации, пожалуйста, помогите мне
спасибо.