我已经提到了为什么在Spring Boot期间找不到bean?和“字段需要找不到类型的bean。”使用mongodb的spring restful API出错
package com.digitalhotelmanagement.digitalhotelmanagement;
@SpringBootApplication
/*
* (scanBasePackages={ "com.digitalhotelmanagement.digitalhotelmanagement",
* "com.digitalhotelmanagement.digitalhotelmanagement.service"})
*/
public class DigitalHotelManagementApplication {
public static void main(String[] args) {
SpringApplication.run(DigitalHotelManagementApplication.class, args);
}
package com.digitalhotelmanagement.digitalhotelmanagement.controller;
@RestController
@RequestMapping("customer")
public class CustomerController {
private static final Logger logger = Logger.getLogger("ClientController");
@Autowired
CustomerService customerService;
/*
* getCustomer getCustomerByEmail createCustomer updateCustomer deleteCustomer
*/
@GetMapping(produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public List<CustomerResponseModel> getCustomer(@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "limit", defaultValue = "10") int limit) throws Exception {
logger.info("Get All Admin List. Pagination parameters: page: " + page + " pageLimit: " + limit);
List<CustomerResponseModel> returnValue = new ArrayList<>();
List<CustomerDTO> customers = customerService.getCustomers(page, limit);
.
.
.
return returnValue;
}
package com.digitalhotelmanagement.digitalhotelmanagement.service;
public interface CustomerService {
CustomerDTO createCustomer(CustomerDTO customer) throws Exception;
List<CustomerDTO> getCustomers(int page, int limit) throws Exception;
}
package com.digitalhotelmanagement.digitalhotelmanagement.implementation;
@Service
public abstract class CustomerServiceImplementation implements CustomerService {
@Autowired
CustomerRepository customerRepository;
@Override
public List<CustomerDTO> getCustomers(int page, int limit) throws Exception {
List<CustomerDTO> returnValue = new ArrayList<>();
Pageable pageableRequest = PageRequest.of(page, limit);
Page<CustomerEntity> customerPage = customerRepository.findAll(pageableRequest);
List<CustomerEntity> customerEntities = customerPage.getContent();
if (customerEntities.isEmpty())
throw new Exception(ErrorMessages.PAGE_ERROR.getErrorMessage());
.
.
.
return returnValue;
}
package com.digitalhotelmanagement.digitalhotelmanagement.repository;
@Repository
public interface CustomerRepository extends PagingAndSortingRepository<CustomerEntity, Integer> {
CustomerEntity findByEmail(String email);
Optional<CustomerEntity> findById(Integer id);
}
2020-10-23 22:19:30.710 WARN 25688 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController':
Unsatisfied dependency expressed through field 'customerServiceImplementation'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'com.digitalhotelmanagement.digitalhotelmanagement.service.CustomerService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Description:
Field customerService in com.digitalhotelmanagement.digitalhotelmanagement.controller.CustomerController required a bean of type 'com.digitalhotelmanagement.digitalhotelmanagement.service.CustomerService' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.digitalhotelmanagement.digitalhotelmanagement.service.CustomerService' in your configuration.
CustomerService只是一个接口,充当CustomerController和CustomerService实施之间的中间人,它实际上在CustomerRepository的帮助下对数据库执行操作。
我正在尝试从MYSQL数据库中检索数据,我总共有7个实体,几乎具有相同的逻辑和不同的功能。
检查此行:
@Service
public abstract class CustomerServiceImplementation implements CustomerService {...}
而它应该是:
@Service
public class CustomerServiceImplementation implements CustomerService {...}
您必须在一个具体的类而不是抽象类中实现CustomerService。因为,抽象类不能被实例化。
问题内容: 每当启动应用程序spring启动时,我都会收到以下错误。 申请开始失败 描述: com.base.model.AbstractDao中的现场会话需要找不到“ org.hibernate.SessionFactory”类型的Bean。 行动: 考虑在配置中定义类型为“ org.hibernate.SessionFactory”的bean。 我添加了我的应用程序的实现: POM.xml 应
我是一名spring boot学习者,所以我一直在尝试创建一些基本的spring boot应用程序。我试图运行开发的应用程序时出错。 我的错误是[[https://i.stack.imgur.com/oyQDi.png][1]][1] java: ItemDetails.java:[软件包名称:io.ajithan.springbootstarter.model] ItemResponse.jav
结构没有问题。spring boot可以扫描UserMapper,但不能扫描UserService。我试着给我的UserService@Mapper组件,然后它就可以被扫描了。但我不知道如何使用其他方法进行扫描。我尝试了@服务,但不起作用。
我搜索了很多stackoverflow,但没有找到解决问题的方法。当将SpringBoot应用程序作为WAR文件部署到Tomcat 8时,我发现以下错误,在本地它确实可以正常工作 有一个接口 和两个实现类 和二等舱 还有Rest服务 所以我不明白Tomcat怎么找不到像boolean这样的原始数据类型,也不明白为什么我在本地运行它时它能工作。 任何帮助都将不胜感激 问候马蒂亚斯
应用程序启动失败 描述: com.base.model.abstractDAO中得字段会话需要类型为“org.hibernate.sessionFactory”得bean,但找不到该bean. 我添加了应用程序的实现: pom.xml 应用程序.属性 我在stackoverflow上查找了相同的错误代码,但没有一个解决方案起作用,因此将它与我的代码一起再次发布在这里。希望别人能指出我错在哪里。
我正在开发Spring Boot应用程序,在启动服务器时遇到了这个错误。我不确定是否错误地定义了任何注释或缺少任何依赖项。任何帮助都将不胜感激。 主要类: UserService类: UserDAO类: @repository公共类UserDAO实现IUserDAO{ Build.gradle: 错误消息: 我看到了所有相关的答案,并尝试实现这些建议,如添加依赖项、在主类中添加符号等。但它显示了相