本文介绍了@SpringBootApplication-ComponentScan无法在新的Eclipse项目中正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用Eclipse(从IntelliJ Idea移出),但是无论我开始写什么新的SpringBoot应用程序,我总是会遇到这个问题.我的主类上的@SpringBootApplication无法按预期工作.我应该能够在不添加@ComponentScann批注的情况下走开(我知道它将使之工作),但是本文的目的是找出原始故障的路由原因.我已经知道解决方法.我的应用始终会显示以下错误消息:

 .____ _ __ _ _/\\/___'_ __ _ _(_)_ __ __ _ _ \ \ \ \(()\ ___ |'_ |'_ | |'_ \/_` | \ \ \ \\\/___)|| _)|||||||(_ | |))))'| ____ |.__ | _ || _ | _ || _ \ __,|////======== | _ | ============= | ___/=/_/_/_/:: Spring Boot ::(v2.0.3.RELEASE)2018-07-18 13:51:22.026信息13936--[restartMain] c.g.w. WorkplaceloggerApplication:使用PID 13936在G488LTN2E上启动WorkplaceloggerApplication(C:\ Projects \ workplacelogger \ bin \ main由212704468在C:\ Projects \ workplacelogger中启动)2018-07-18 13:51:22.026信息13936 --- [restartedMain] c.g.w. WorkplaceloggerApplication:未设置活动配置文件,恢复为默认配置文件:默认2018-07-18 13:51:22.075信息13936 --- [restartedMain] ConfigServletWebServerApplicationContext:刷新org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7f70a763:启动日期[2018年7月18日星期三13:51:22 CEST];上下文层次结构的根2018-07-18 13:51:22.959 INFO 13936 --- [restartedMain] o.s.b.f.s.DefaultListableBeanFactory:用不同的定义覆盖bean'httpRequestHandlerAdapter'的bean定义:替换[Root bean:class [null];范围=;abstract = false;lazyInit = false;autowireMode = 3;dependencyCheck = 0;autowireCandidate = true;primary = false;factoryBeanName = org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration $ EnableWebMvcConfiguration;factoryMethodName = httpRequestHandlerAdapter;initMethodName = null;destroyMethodName =(推断);在类路径资源[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration $ EnableWebMvcConfiguration.class]中定义,并带有[Root bean:class [null];范围=;abstract = false;lazyInit = false;autowireMode = 3;dependencyCheck = 0;autowireCandidate = true;primary = false;factoryBeanName = org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;factoryMethodName = httpRequestHandlerAdapter;initMethodName = null;destroyMethodName =(推断);在类路径资源[org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]中定义2018-07-18 13:51:23.592信息13936--[restartMain] o.s.b.w.embedded.tomcat.TomcatWebServer:使用端口初始化的Tomcat:8080(http)2018-07-18 13:51:23.609信息13936 --- [restartedMain] o.apache.catalina.core.StandardService:正在启动服务[Tomcat]2018-07-18 13:51:23.609信息13936-[[restartedMain] org.apache.catalina.core.StandardEngine:启动Servlet引擎:Apache Tomcat/8.5.312018-07-18 13:51:23.609信息13936-[ost-startStop-1] oacatalina.core.AprLifecycleListener:在Java上找不到基于APR的Apache Tomcat本机库,该库允许在生产环境中实现最佳性能.library.path:[C:\ Program Files \ Java \ jre1.8.0_171 \ bin; C:\ Windows \ Sun \ Java \ bin; C:\ Windows \ system32; C:\ Windows; C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin; C:/Program Files/Java/jre1.8.0_171/lib/amd64; C:\ Program Files(x86)\ Common Files \ Oracle \ Java \ javapath; C:\ Windows \ system32; C:\ Windows; C:\ Windows \ System32 \ Wbem; C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \; C:\ Program Files(x86)\ NVIDIA Corporation \ PhysX \ Common; C:\ Program Files \ Java \ jdk1.8.0_171; C:\ Program Files \ Git \ cmd; C:\ ProgramData \ chocolatey \ bin; C:\ Program Files \ Java\ jdk1.8.0_171 \ bin; C:\ Program Files \ nodejs \; C:\ Python27 \; C:\ Python27 \ Scripts \; C:\ ChromeDriver \ ;; C:\ Program Files \ Cloud Foundry; C:\Users \ 212704468 \ AppData \ Local \ Microsoft \ WindowsApps; C:\ Users \ 212704468 \ AppData \漫游\ npm; C:\ Program Files \ Microsoft VS Code \ bin; C:\ Users \ 212704468 \ AppData \ Local \ Programs \ Fiddler; C:\ sts-bundle \ sts-3.9.4.RELEASE ;;.]2018-07-18 13:51:23.758信息13936-[ost-startStop-1] o.a.c.c.C. [Tomcat].[localhost].[/]:初始化Spring嵌入式WebApplicationContext2018-07-18 13:51:23.758信息13936-[ost-startStop-1] o.s.web.context.ContextLoader:根WebApplicationContext:初始化在1683毫秒内完成2018-07-18 13:51:23.892信息13936-[ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean:Servlet调度程序Servlet映射到[/]2018-07-18 13:51:23.908信息13936 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:将过滤器:'characterEncodingFilter'映射到:[/*]2018-07-18 13:51:23.909信息13936-[ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:将过滤器:'hiddenHttpMethodFilter'映射到:[/*]2018-07-18 13:51:23.909信息13936-[ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:将过滤器:'httpPutFormContentFilter'映射到:[/*]2018-07-18 13:51:23.909信息13936 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean:将过滤器:'requestContextFilter'映射到:[/*]2018-07-18 13:51:23.942 WARN 13936 --- [restartedMain] ConfigServletWebServerApplicationContext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'eventServiceDbImpl'的bean时出错:不满意通过字段"eventRepository"表示的依赖关系;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为"com.ge.workplacelogger.repositories.EventRepository"的合格Bean:期望至少有1个有资格作为自动装配候选的Bean.依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}2018-07-18 13:51:23.942信息13936-[[restartMain] o.apache.catalina.core.StandardService:停止服务[Tomcat]2018-07-18 13:51:23.959 INFO 13936 --- [restartedMain] ConditionEvaluationReportLoggingListener:启动ApplicationContext时出错.要显示条件报告,请在启用调试"的情况下重新运行您的应用程序.2018-07-18 13:51:24.159错误13936 --- [restartedMain] o.s.b.d.LoggingFailureAnalysisReporter:****************************申请开始失败****************************描述:com.ge.workplacelogger.services.EventServiceDbImpl中的字段eventRepository需要找不到类型为"com.ge.workplacelogger.repositories.EventRepository"的bean.行动:考虑在配置中定义类型为"com.ge.workplacelogger.repositories.EventRepository"的bean. 

所以,这是我正在使用的代码

主类:

 程序包com.ge.workplacelogger;导入org.springframework.boot.SpringApplication;导入org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication公共类WorkplaceloggerApplication {公共静态void main(String [] args){SpringApplication.run(WorkplaceloggerApplication.class,args);}} 

存储库界面:

 程序包com.ge.workplacelogger.repositories;导入java.util.List;导入org.springframework.data.repository.CrudRepository;导入org.springframework.stereotype.Repository;导入com.ge.workplacelogger.models.Event;导入com.ge.workplacelogger.models.Worker;@资料库公共接口EventRepository扩展了CrudRepository< Event,Integer>.{void saveEvent(Event event);void deleteEvent(Event event);List< Event>findAllEvents();事件findEventByEventId(Integer eventId);List< Event>findEventsByWorker(工人工人);} 

最后,是我要@Autowire EventRepository的服务:

 程序包com.ge.workplacelogger.services;导入java.util.List;导入org.springframework.beans.factory.annotation.Autowired;导入org.springframework.stereotype.Service;导入com.ge.workplacelogger.models.Event;导入com.ge.workplacelogger.models.Worker;导入com.ge.workplacelogger.repositories.EventRepository;@服务公共类EventServiceDbImpl实现EventService {@AutowiredEventRepository eventRepository;@Override公共无效saveEvent(事件事件){eventRepository.saveEvent(event);}@Override公共无效deleteEvent(事件事件){eventRepository.deleteEvent(event);}@Override公共列表<事件>findAllEvents(){返回eventRepository.findAllEvents();}@Override公共事件findEventByEventId(Integer eventId){返回eventRepository.findEventByEventId(eventId);}@Override公共列表<事件>findEventsByWorker(工人工人){返回eventRepository.findEventsByWorker(worker);}} 

据我了解,主类(位于com.ge.workplacelogger包中)的@SpringBootApplication将在所有子包上用作@ComponentScan.我所有的服务,存储库,模型都在com.ge.workplacelogger包的子包中,所以我真的不知道出什么问题了.这可能是一个荒谬的问题,但是与Eclipse有什么关系吗?以前从来没有IntelliJ有任何问题.

非常感谢您的提前答复!

这也是我的实体,供您评估.

 包com.ge.workplacelogger.models;导入java.time.LocalDateTime;导入javax.persistence.Entity;导入javax.persistence.FetchType;导入javax.persistence.GeneratedValue;导入javax.persistence.GenerationType;导入javax.persistence.Id;导入javax.persistence.JoinColumn;导入javax.persistence.ManyToOne;导入javax.persistence.Table;@实体@桌子公开课活动{@ID@GeneratedValue(策略= GenerationType.AUTO)私有Integer eventId;@ManyToOne(获取= FetchType.LAZY)@JoinColumn(name ="workerId")私人工人私人布尔值登录;私有LocalDateTime时间戳;私有字符串注释;公共事件(){}公共事件(整数eventId,Worker worker,布尔值LogIn,LocalDateTime时间戳记,字符串注释){this.eventId = eventId;this.worker =工人;this.logIn =登录;this.timestamp =时间戳;this.comment =评论;}public Integer getEventId(){返回eventId;}public void setEventId(Integer eventId){this.eventId = eventId;}公共工作者getWorker(){返还工人;}公共无效setWorker(工人工人){this.worker =工人;}公共布尔isLogIn(){返回登录;}public void setLogIn(boolean logIn){this.logIn =登录;}公共LocalDateTime getTimestamp(){返回时间戳;}public void setTimestamp(LocalDateTime timestamp){this.timestamp =时间戳;}公共字符串getComment(){返回评论;}public void setComment(String comment){this.comment =评论;}@Override公共字符串toString(){返回事件[eventId ="+ eventId +",worker ="+ worker +",logIn ="+ logIn +",timestamp ="+时间戳+,comment =" +评论+]";}} 

Build.gradle:

  buildscript {ext {springBootVersion ='2.0.3.RELEASE'}储存库{mavenCentral()}依赖项{classpath("org.springframework.boot:spring-boot-gradle-plugin:$ {springBootVersion}")}}应用插件:"java"套用外挂程式:'eclipse'应用插件:"org.springframework.boot"应用插件:"io.spring.dependency-management"组='com.ge'版本='0.0.1-SNAPSHOT'sourceCompatibility = 1.8储存库{mavenCentral()}依赖项{编译('org.springframework.boot:spring-boot-starter-data-jpa')编译('org.springframework.boot:spring-boot-starter-data-rest')编译('org.springframework.boot:spring-boot-starter-jdbc')编译('org.springframework.boot:spring-boot-starter-thymeleaf')编译('org.springframework.boot:spring-boot-starter-web')运行时('org.springframework.boot:spring-boot-devtools')运行时('org.postgresql:postgresql')testCompile('org.springframework.boot:spring-boot-starter-test')} 

这是无法在此处插入的超长报告的末尾:)调试= true

 排除项:-----------org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration无条件的类:----------------------org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfigurationorg.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfigurationorg.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfigurationorg.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfigurationorg.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration2018-07-18 16:49:24.410调试7068 --- [restartedMain] o.s.b.d.LoggingFailureAnalysisReporter:由于异常,应用程序无法启动org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为'entityManagerFactory'的bean在org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:686)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:625)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:312)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:131)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1611)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1363)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]中在org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)〜[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)〜[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)〜[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)上[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)上[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)上[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)上[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)上[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]在com.ge.workplacelogger.WorkplaceloggerApplication.main(WorkplaceloggerApplication.java:14)[main/:na]在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[na:1.8.0_171]在sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)〜[na:1.8.0_171]在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)〜[na:1.8.0_171]在java.lang.reflect.Method.invoke(未知来源)〜[na:1.8.0_171]在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-2.0.3.RELEASE.jar:2.0.3.RELEASE]2018-07-18 16:49:24.411错误7068 --- [restartedMain] o.s.b.d.LoggingFailureAnalysisReporter:****************************申请开始失败****************************描述:com.ge.workplacelogger.services.EventServiceDbImpl中的字段eventRepository需要找不到名为'entityManagerFactory'的bean.行动:考虑在配置中定义一个名为"entityManagerFactory"的bean. 

Application.properties

  spring.datasource.url = jdbc:postgres://localhost:5432/workplaceloggerspring.datasource.username = postgresspring.datasource.password =密码spring.jpa.hibernate.ddl-auto =创建-放置spring.logging.level.org.hibernate.SQL =调试spring.jpa.show-sql = true pring.autoconfigure.exclude = org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration调试=真 
解决方案

我发现应用程序属性中的一个错误导致了该问题:

原始行:

  spring.datasource.url = jdbc:postgres://localhost:5432/workplacelogger 

正确的行:

  spring.datasource.url = jdbc:postgresql://localhost:5432/workplacelogger 

也删除了应用程序属性中的以下行,因为先前的解析器"建议:

  spring.autoconfigure.exclude = org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration 

该代码现在可以运行,并且进行了一些其他小的更正,这些不是本票证的内容.这是程序员应该不时退后一步以找到导致错误的路由原因的证据:)我迷失了细节,并且花了很多时间在我的家庭项目中找到这样的错别字"./p>

谢谢大家的光临!

I recently started using Eclipse (moved from IntelliJ Idea) but whatever new SpringBoot app I start writing, I always get this problem. The @SpringBootApplication on my main class does not work as intended. I should be able to get away without adding the @ComponentScann annotation (I know it would make it work), but the intention of this post is to find out the route cause of the original failure. I already know work-arounds. My app always breaks with the following error message:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-07-18 13:51:22.026  INFO 13936 --- [  restartedMain] c.g.w.WorkplaceloggerApplication         : Starting WorkplaceloggerApplication on G488LTN2E with PID 13936 (C:\Projects\workplacelogger\bin\main started by 212704468 in C:\Projects\workplacelogger)
2018-07-18 13:51:22.026  INFO 13936 --- [  restartedMain] c.g.w.WorkplaceloggerApplication         : No active profile set, falling back to default profiles: default
2018-07-18 13:51:22.075  INFO 13936 --- [  restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7f70a763: startup date [Wed Jul 18 13:51:22 CEST 2018]; root of context hierarchy
2018-07-18 13:51:22.959  INFO 13936 --- [  restartedMain] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'httpRequestHandlerAdapter' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration; factoryMethodName=httpRequestHandlerAdapter; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]]
2018-07-18 13:51:23.592  INFO 13936 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-07-18 13:51:23.609  INFO 13936 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-07-18 13:51:23.609  INFO 13936 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-18 13:51:23.609  INFO 13936 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_171\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_171/bin/server;C:/Program Files/Java/jre1.8.0_171/bin;C:/Program Files/Java/jre1.8.0_171/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Java\jdk1.8.0_171;C:\Program Files\Git\cmd;C:\ProgramData\chocolatey\bin;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Program Files\nodejs\;C:\Python27\;C:\Python27\Scripts\;C:\ChromeDriver\;;C:\Program Files\Cloud Foundry;C:\Users\212704468\AppData\Local\Microsoft\WindowsApps;C:\Users\212704468\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\Users\212704468\AppData\Local\Programs\Fiddler;C:\sts-bundle\sts-3.9.4.RELEASE;;.]
2018-07-18 13:51:23.758  INFO 13936 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-07-18 13:51:23.758  INFO 13936 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1683 ms
2018-07-18 13:51:23.892  INFO 13936 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-07-18 13:51:23.908  INFO 13936 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-18 13:51:23.909  INFO 13936 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-18 13:51:23.909  INFO 13936 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-18 13:51:23.909  INFO 13936 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-18 13:51:23.942  WARN 13936 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventServiceDbImpl': Unsatisfied dependency expressed through field 'eventRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.ge.workplacelogger.repositories.EventRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2018-07-18 13:51:23.942  INFO 13936 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-07-18 13:51:23.959  INFO 13936 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-07-18 13:51:24.159 ERROR 13936 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field eventRepository in com.ge.workplacelogger.services.EventServiceDbImpl required a bean of type 'com.ge.workplacelogger.repositories.EventRepository' that could not be found.


Action:

Consider defining a bean of type 'com.ge.workplacelogger.repositories.EventRepository' in your configuration.

So, here is the code that I am using

Main class:

package com.ge.workplacelogger;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WorkplaceloggerApplication {

    public static void main(String[] args) {
        SpringApplication.run(WorkplaceloggerApplication.class, args);

    }
}

Repository interface:

package com.ge.workplacelogger.repositories;

import java.util.List;

import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.ge.workplacelogger.models.Event;
import com.ge.workplacelogger.models.Worker;


@Repository
public interface EventRepository extends CrudRepository<Event, Integer> {

  void saveEvent(Event event);

  void deleteEvent(Event event);

  List<Event> findAllEvents();

  Event findEventByEventId(Integer eventId);

  List<Event> findEventsByWorker(Worker worker);
}

and finally, the Service where I would like to @Autowire the EventRepository:

package com.ge.workplacelogger.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ge.workplacelogger.models.Event;
import com.ge.workplacelogger.models.Worker;
import com.ge.workplacelogger.repositories.EventRepository;

@Service
public class EventServiceDbImpl implements EventService {

  @Autowired
  EventRepository eventRepository;

  @Override
  public void saveEvent(Event event) {
    eventRepository.saveEvent(event);
  }

  @Override
  public void deleteEvent(Event event) {
    eventRepository.deleteEvent(event);
  }

  @Override
  public List<Event> findAllEvents() {
    return eventRepository.findAllEvents();
  }

  @Override
  public Event findEventByEventId(Integer eventId) {
    return eventRepository.findEventByEventId(eventId);
  }

  @Override
  public List<Event> findEventsByWorker(Worker worker) {
    return eventRepository.findEventsByWorker(worker);
  }
}

As far as I understand, the @SpringBootApplication on my main class (in package com.ge.workplacelogger) will work as @ComponentScan on all subpackages. All my services, repositories, models are in a subpackage of the package com.ge.workplacelogger, so I really have no ide what goes wrong. It might be a ridiculous question, but does it have anything to do with Eclipse? Never had any problem with IntelliJ before.

Thank you very much for the answer in advance!

EDIT:Here is my entity as well for evaluation.

package com.ge.workplacelogger.models;

import java.time.LocalDateTime;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table
public class Event {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Integer eventId;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "workerId")
  private Worker worker;

  private boolean logIn;
  private LocalDateTime timestamp;
  private String comment;

  public Event() {
  }

  public Event(Integer eventId, Worker worker, boolean logIn, LocalDateTime timestamp, String comment) {
    this.eventId = eventId;
    this.worker = worker;
    this.logIn = logIn;
    this.timestamp = timestamp;
    this.comment = comment;
  }

  public Integer getEventId() {
    return eventId;
  }

  public void setEventId(Integer eventId) {
    this.eventId = eventId;
  }

  public Worker getWorker() {
    return worker;
  }

  public void setWorker(Worker worker) {
    this.worker = worker;
  }

  public boolean isLogIn() {
    return logIn;
  }

  public void setLogIn(boolean logIn) {
    this.logIn = logIn;
  }

  public LocalDateTime getTimestamp() {
    return timestamp;
  }

  public void setTimestamp(LocalDateTime timestamp) {
    this.timestamp = timestamp;
  }

  public String getComment() {
    return comment;
  }

  public void setComment(String comment) {
    this.comment = comment;
  }

  @Override
  public String toString() {
    return "Event [eventId=" + eventId + ", worker=" + worker + ", logIn=" + logIn + ", timestamp=" + timestamp
        + ", comment=" + comment + "]";
  }
}

EDIT 2:Build.gradle:

buildscript {
    ext {
        springBootVersion = '2.0.3.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.ge'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-jdbc')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('org.postgresql:postgresql')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

EDIT 3:Here is the end of the super-long report that could not be inserted in here :)debug = true

Exclusions:
-----------

    org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration


Unconditional classes:
----------------------

    org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration

    org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration

    org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration

    org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration

    org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration



2018-07-18 16:49:24.410 DEBUG 7068 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : Application failed to start due to an exception

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:686) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1210) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:625) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:444) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:312) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:131) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1611) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1363) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at com.ge.workplacelogger.WorkplaceloggerApplication.main(WorkplaceloggerApplication.java:14) [main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.3.RELEASE.jar:2.0.3.RELEASE]

2018-07-18 16:49:24.411 ERROR 7068 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field eventRepository in com.ge.workplacelogger.services.EventServiceDbImpl required a bean named 'entityManagerFactory' that could not be found.


Action:

Consider defining a bean named 'entityManagerFactory' in your configuration.

EDIT 4:Application.properties

spring.datasource.url=jdbc:postgres://localhost:5432/workplacelogger
spring.datasource.username=postgres
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create-drop
spring.logging.level.org.hibernate.SQL=debug
spring.jpa.show-sql=true pring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
debug=true
解决方案

I have found a mistake in the application properties that caused the issue:

original line:

spring.datasource.url=jdbc:postgres://localhost:5432/workplacelogger

correct line:

spring.datasource.url=jdbc:postgresql://localhost:5432/workplacelogger

Also deleted the following line in application properties as the previous "resolver" has suggested:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

The code runs now with some additional minor corrections that are not the subject of this ticket.Here is the evidence that a programmer should step back from time to time to find the route cause of the error :) I was lost in the details and it took a lot of time to find such a "typo" in my home project.

Thank you all for your time!

这篇关于@SpringBootApplication-ComponentScan无法在新的Eclipse项目中正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 02:11