[英]Spring-Boot error creating bean, startup fails ca. 50% of Time
I have a Spring-Boot application, where the startup sometimes fails, and sometimes, without changing anything in the Code, it works. 我有一个Spring-Boot应用程序,其中的启动有时会失败,有时,如果不更改代码中的任何内容,它将正常工作。 Here's the Error: 这是错误:
Parameter 1 of constructor in ch.post.pf.quick2lunch.business.service.OrderService required a bean of type 'ch.post.pf.quick2lunch.repository.MenuOrderRepo' that could not be found.
Action:
Consider defining a bean of type 'ch.post.pf.quick2lunch.repository.MenuOrderRepo' in your configuration.
06-Jul-2018 10:41:34.287 SCHWERWIEGEND [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/quick2lunch]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:441)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
The Annotaions should be okay. 注释应该没问题。
Here's The MenuOrderRepo: 这是MenuOrderRepo:
@Repository
public interface MenuOrderRepo extends JpaRepository<MenuOrder, Long> {
}
And here's the OrderService: 这是OrderService:
@Service
public class OrderService {
private final OrderRepo orderRepo;
private final MenuOrderRepo menuOrderRepo;
@Autowired
public OrderService(final OrderRepo orderRepo, final MenuOrderRepo menuOrderRepo) {
this.orderRepo = orderRepo;
this.menuOrderRepo = menuOrderRepo;
}
It's my first Project with Spring-Boot and I changed nothing in the configuration. 这是我第一个使用Spring-Boot的项目,我在配置中没有做任何更改。
You need to make your boot application aware about your repository classes. 您需要使引导应用程序了解您的存储库类。
so add @EnableJpaRepositories("ch.post.pf.quick2lunch.repository")
in your spring boot main class. 因此,在您的Spring Boot主类中添加@EnableJpaRepositories("ch.post.pf.quick2lunch.repository")
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.