我正在使用Spring Boot,Hibernate和My sql,但出现错误。
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration'的bean时出错:通过构造函数参数0表示的依赖关系未满足;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org / springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $ Hikari.class]中定义的名称为“ dataSource”的bean时出错:通过工厂方法进行Bean实例化失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'引发了异常;嵌套异常是java.lang.IllegalStateException:无法在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)加载驱动程序类:com.mysql.jdbc.Driver〜[spring-beans-5.0。 9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9 .RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans .factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean( AbstractAutowireCapableBeanFactory.java:535)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory处。 support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton( DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring -beans-5.0.9.RELEASE.jar:5.0.9.RELEASE],位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.9.RELEASE。 jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support .AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java: 535)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)〜[spring-beans-5.0 .9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0.9.RELEASE.jar :5.0.9.RELEASE],位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry。 getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)上的[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]〜[spring-beans-5.0.9。在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089)〜[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]中的RELEASE.jar:5.0.9.RELEASE] org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859)〜[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:550)〜[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refre sh(ServletWebServerApplicationContext.java:140)〜[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780)[spring-boot- 2.0.5.RELEASE.jar:2.0.5.RELEASE]位于org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:333)[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java) :1277)位于org.springframework.boot.SpringApplication.run(SpringApplication.java:1265)的[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] [spring-boot-2.0.5.RELEASE。 jar:2.0.5.RELEASE]在com.trial.TrialApplication.main(TrialApplication.java:15)[classes /:na]原因:org.springframework.beans.factory.BeanCreationException:创建名称为“ dataSource”的bean时出错在类路径资源[org / springframework / boot / autoconfigure / jdbc / DataSo中定义urceConfiguration $ Hikari.class]:通过工厂方法实例化Bean失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'引发了异常;嵌套的异常是java.lang.IllegalStateException:无法在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)〜[spring-beans-5.0。上加载驱动程序类:com.mysql.jdbc.Driver。 9.RELEASE.jar:5.0.9.RELEASE]位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9 .RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans .factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean( AbstractAutowireCapableBeanFactory.java:495)〜[sprin g-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE],位于org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:317)〜[spring-beans-5.0。 9.RELEASE.jar:5.0.9.RELEASE]位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9 [RELEASE],位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE],位于org.springframework.beans .factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate( DependencyDescriptor.java:251)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135)〜[spring -beans-5.0.9.RELEASE .jar:5.0.9.RELEASE]位于org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]中。 support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ...省略了28个常见框架造成原因:org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'抛出异常;嵌套异常是java.lang.IllegalStateException:无法在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)〜[spring-beans-5.0。中加载驱动程序类:com.mysql.jdbc.Driver。 9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9 [.RELEASE] ...省略了41个共同的框架原因:java.lang.IllegalStateException:无法在org.springframework.util.Assert.state(Assert.java:94)加载驱动程序类:com.mysql.jdbc.Driver〜 spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE],位于org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:224)〜[spring-boot-autoconfigure-2.0.5 .RELEASE.jar:2.0.5.RELEASE],位于org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176)〜[spring-boot-auto在org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43)上配置[configure-2.0.5.RELEASE.jar:2.0.5.RELEASE]〜[spring-boot-autoconfigure-2.0.5.RELEASE .jar:2.0.5.RELEASE],位于org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $ Hikari.dataSource(DataSourceConfiguration.java:83)〜[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0。 5.RELEASE]在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[na:1.8.0_181]在sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)〜[na:1.8.0_181]在sun.reflect.DelegatingMethodAccessorImpl .invoke(未知来源)〜[na:1.8.0_181],位于java.lang.reflect.Method.invoke(未知来源)〜[na:1.8.0_181],位于org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java:154)〜[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ...省略了42个常见框架
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.bookstore</groupId>
<artifactId>bookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bookstore</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.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>
</properties>
<dependencies>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
实体类别为
package com.trial.hibernate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Employee {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
private String name;
private String phone;
}
属性文件为
server.port=8181
spring.thymeleaf.cache=false
# create and drop tables and sequences, loads import.sql
spring.jpa.hibernate.ddl-auto=create
# database settings
spring.datasource.url=jdbc:mysql://localhost:3306/bookstore?useSSL=false
spring.datasource.username=root
spring.datasource.password=oracle
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
github存储库链接为https://github.com/dishankgoyal/springsBoot
我该如何解决?
答案 0 :(得分:1)
我发现您的项目在我的末端运行良好,您可能会尝试在末端完成一些工作。
尝试更改为spring.datasource.driverClassName=com.mysql.jdbc.Driver
从主要班级中删除@ComponentScan()
,然后仅将@SpringBootApplication
留在那里。
@SpringBootApplication 公共类TrialApplication {
public static void main(String[] args) {
SpringApplication.run(TrialApplication.class, args);
}
}
按项目清理项目->重建/清理或运行命令mvn clean install
或删除.m2/repository
或重新导入项目或重新启动IDE /系统可能会有所帮助。