当我尝试将Springboot appliction与MySql连接时,我变得像这样,我对此一无所知
org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为bean的错误 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': 通过构造函数参数0表示的不满足的依赖关系; 嵌套异常为 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为“ dataSource”的bean [org / springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $ Hikari.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource'引发异常;嵌套异常为 java.lang.IllegalStateException:无法加载驱动程序类: com.mysql.jdbc.Driver 在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218)处 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341)处 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)上 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:392) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)处 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)上 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) 〜[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) 〜[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) 〜[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) 〜[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) 〜[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) 〜[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:311) 〜[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) 〜[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) 〜[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在com.example.demo.DemoApplication.main(DemoApplication.java:10)〜[classes /:na] 引起原因:org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为“ dataSource”的bean [org / springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $ Hikari.class]: 通过工厂方法实例化Bean失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource'引发异常;嵌套异常为 java.lang.IllegalStateException:无法加载驱动程序类: com.mysql.jdbc.Driver 在org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)处 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)上 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251)处 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] ...省略28个通用框架 原因:org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂 方法“ dataSource”抛出异常;嵌套异常为 java.lang.IllegalStateException:无法加载驱动程序类: com.mysql.jdbc.Driver 在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] ...省略了42个通用框架 引起原因:java.lang.IllegalStateException:无法加载驱动程序类:com.mysql.jdbc.Driver 在org.springframework.util.Assert.state(Assert.java:94)〜[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:222) 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:174) 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43) 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $ Hikari.dataSource(DataSourceConfiguration.java:85) 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $ Hikari $$ EnhancerBySpringCGLIB $$ 12ce4fa3.CGLIB $ dataSource $ 0() 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $ Hikari $$ EnhancerBySpringCGLIB $$ 12ce4fa3 $$ FastClassBySpringCGLIB $$ 4638b298.invoke() 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) 〜[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)处 〜[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE] 在org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration $ Hikari $$ EnhancerBySpringCGLIB $$ 12ce4fa3.dataSource() 〜[spring-boot-autoconfigure-2.1.6.RELEASE.jar:2.1.6.RELEASE] 在java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机 方法)〜[na:na] 在java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 〜[na:na] 在java.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 〜[na:na] 在java.base / java.lang.reflect.Method.invoke(Method.java:567)〜[na:na] 在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) 〜[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE] ...省略了43个共同的框架
''''
spring boot应用程序类
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
System.out.println("Application Started");
}
}
控制器
package com.example.demo.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.example.demo.DaoImpl.UserDaoImpl;
import com.example.demo.dto.UserDTO;
@Controller
public class HomeController {
@Autowired
UserDaoImpl udi;
@RequestMapping("home")
public ModelAndView home() {
ModelAndView mv = new ModelAndView("home");
System.out.println("function is runnning");
UserDTO ud = new UserDTO();
ud.setEmail("abcd@gmail.com");
ud.setName("abce");
udi.save(ud);
return mv;
}
}
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- -->
<!-- JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- -->
<!-- Use MySQL Connector-J -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Application.properties
spring.mvc.view.prefix=/pages/
spring.mvc.view.suffix=.jsp
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.database=MYSQL
spring.datasource.url = jdbc:mysql://localhost:3306/demo
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
我尝试过在另一个系统的另一个spring工具套件中进行同样的操作 它在那里工作,但在这里不工作。 请帮助我解决这个问题