构建时出现此错误。我在这里提到了其他答案,但是没有一个对我有用。
application.properties
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/externalPoc
spring.datasource.username=postgres
spring.datasource.password=
spring.database.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=false
hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
仓库:
@Repository
public interface CardRepository extends JpaRepository<CardRegistration, Serializable> {
Optional<Card> findByUuid(String uuid);
}
实体:
@Entity
public class Card extends AbstractBaseEntity implements Serializable {
String uuid;
String validFrom;
String validTo;
public String getValidFrom() {
return validFrom;
}
public void setValidFrom(String validFrom) {
this.validFrom = validFrom;
}
public String getValidTo() {
return validTo;
}
public void setValidTo(String validTo) {
this.validTo = validTo;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}
和pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.start.new.project</groupId>
<artifactId>externalAdapterPoc</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>externalPoc</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<springfox-swagger.version>2.7.0</springfox-swagger.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1206-jdbc42</version><!--$NO-MVN-MAN-VER$-->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
<!-- swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20171018</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
和主类(Spring Boot应用程序)
@SpringBootApplication
@EnableJpaRepositories(basePackages = "com.start.new.project.externalPoc.model.repository")
@EntityScan(basePackages = "com.start.new.project.externalPoc.model")
public class ExternalPocApplication {
public static void main(String[] args) {
SpringApplication.run(ExternalPocApplication.class, args);
}
@Bean
public MapperFacade mapper() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
return mapperFactory.getMapperFacade();
}
}
我从.m2目录中删除了所有文件夹。再次运行mvn clean安装。得到了同样的错误。
服务类自动装配资源库。
控制器使用@RestController批注。
这是确切的原因:
引起原因:org.springframework.beans.factory.BeanCreationException:
创建名称为“((内部bean)#4d3ca6c7”)的bean时出错:无法解析
设置构造函数时对bean'entityManagerFactory'的引用
论点嵌套异常为
org.springframework.beans.factory.NoSuchBeanDefinitionException:否
名为“ entityManagerFactory”的bean可用
最佳答案
从https://start.spring.io创建一个虚拟项目(选择Switch to the full version and tick PostGres, for example
),然后将类添加到该项目中。
这样,您就不必担心依赖项,并且默认情况下您将获得最新信息。我昨天用过它,它对我来说就像一种魅力。
关于java - NoSuchBeanDefinitionException:没有可用的名为“entityManagerFactory”的bean,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50578216/