- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近开始使用 Eclipse(从 IntelliJ Idea 迁移而来),但无论我开始编写新的 SpringBoot 应用程序,我总是遇到这个问题。我的主类上的 @SpringBootApplication 没有按预期工作。我应该能够在不添加 @ComponentScann 注释的情况下逃脱(我知道它会让它起作用),但这篇文章的目的是找出最初失败的原因。我已经知道解决方法。我的应用程序总是中断并显示以下错误消息:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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.
所以,这是我正在使用的代码
主类:
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);
}
}
存储库接口(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);
}
最后,我想@Autowire 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);
}
}
据我所知,我的主类(在包 com.ge.workplacelogger 中)上的 @SpringBootApplication 将在所有子包上作为 @ComponentScan 工作。我所有的服务、存储库、模型都在 com.ge.workplacelogger 包的子包中,所以我真的不知道哪里出了问题。这可能是一个荒谬的问题,但它与 Eclipse 有什么关系吗?以前从未遇到过 IntelliJ 的任何问题。
非常感谢您提前的回答!
编辑:这也是我的实体,供评估。
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 + "]";
}
}
编辑 2:构建.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')
}
编辑 3:无法插入的超长报告到此结束:)调试=真
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.
编辑 4:应用程序.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
最佳答案
@SpringBootApplication
确实包含了 @ComponentScan
。
来自 Getting Started - Building an Application with Spring Boot :
@SpringBootApplication is a convenience annotation that adds all of the following:
@Configuration tags the class as a source of bean definitions for the application context.
@EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings.
Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet.
@ComponentScan tells Spring to look for other components, configurations, and services in the hello package, allowing it to find the controllers.
在此处进一步阅读 SO:Configuration using annotation @SpringBootApplication
在我看来,问题的根源可能是缺少您在报告中提到的 entityManagerFactory
bean。向上滚动报告,我们会注意到出现的“排除项”部分:
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
SpringBootApplication exclude when ComponentScanning other @SpringBootApplications帮我完成了剩下的路。您的应用程序属性稍微搞砸了。请注意这一行:
spring.jpa.show-sql=true pring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
我认为这可能是您原始文件中的 2 行。无论如何,排除 DataSourceAutoConfiguration
可能是这里的错误。尝试删除:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
关于java - @SpringBootApplication - ComponentScan 在新的 Eclipse 项目中没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51401780/
我在阻止 Spring Boot 自动配置某些类(在本例中:SolrAutoConfiguration)时遇到了一些困难。为了说明这一点,我设置了一个简化得多的示例: https://github.c
我在阻止 Spring Boot 自动配置某些类时遇到了一些困难(在本例中:SolrAutoConfiguration)。为了说明,我设置了一个大大简化的示例: https://github.com/
根据我的理解,使用@SpringBootApplication相当于拥有@EnableAutoConfiguration和@ComponentScan。由于这个原因,我不明白为什么Spring找不到我
静态文件位于: src/main/resources/static/ js CSS 图片 等.. 无论我做什么,文件都不会被拾取。我试过 addResourceHandlers 但似乎没有任何效果。
我写了一个基于 Spring Boot 的应用程序,但是当我将所有类(模型、用 @restController 注释的 Controller )放在 SpringBoot 存在的同一个包中时,它就可以
我在 nexus 上发布了一个具有包 ID 的公共(public)库 x.xx.common 包含常见Feign客户端代理接口(interface)子包 使用这个库的项目有包 id。 x.xx.acc
我正在努力在简单的 SpringBootApplication 中加载配置。当我尝试打印配置类中的变量时,它们始终为空。 最初,我在 WatchApplication.java 中有可配置变量。然而,
我的 Spring Boot 配置有问题。 我使用 https://start.spring.io/ 创建了基础 Spring Boot 项目 我有一个问题,配置仅适用于子目录中的类: 我尝试过注释@
使用@WebMvcTest 将通过查找@SpringBootConfiguration 类(例如@SpringBootApplication)自动配置所有web 层bean。 如果配置类在不同的包里,
我有一个带有 Autowiring 功能的简单 Spring 应用程序 AppMain,我不想在其中使用任何显式 XML 配置。 在我的 TaskScheduler 组件中,我想将 ThreadPoo
没有@SpringBootApplication,Spring boot应用程序如何工作? 在我们的项目中,我们使用了@Component、@Configuration以及带有@Bean注解的bean
我正在尝试将 spring、非启动应用程序迁移到启动应用程序。当前构建了一个 war 文件。正在关注these说明,我正在逐步完成迁移步骤。 我发现 @SpringBootApplication 注释
我对 SpringBoot 还很陌生。我创建了一个带有服务类的示例应用程序。 下面是我的SpringBootApplication类 @SpringBootApplication public cla
my earlier question 的答案说我应该使用 @SpringBootApplication(scanBasePackages = {"path.to.your.project.root"
我有一个 SpringBootApplication,我想从我的属性文件中读取一个值。 我的@SpringBootApplication类是这样的: @SpringBootApplication @C
如何使用@SpringBootApplication注释从类运行代码。我想运行我的代码而不调用 Controller 并从终端而不是网络浏览器获取信息。我尝试在@SpringBootApplicati
我在 Spring Boot 初始化时遇到了问题。我在一个简单的 Spring Boot 项目中有这个结构。 com.project.name |----App.java (Annoted with
我对 STS 很陌生。我在stackoverflow中搜索了这个错误。我没有找到正确的匹配答案。 我可以在 STS 的 MavenDependencies 部分中看到该类,但无法在我的 java 类中
有没有办法在运行mvn spring-boot:run时指定运行哪个SpringBootApplication的主类? docs说我可以使用 mainClass 参数来指定要运行的主类。但我不确定如何
我试过 @JdbcTest关于以下项目结构。 . ├── pom.xml └── src ├── main │ ├── java │ │ └── com │
我是一名优秀的程序员,十分优秀!