在配置application.yml文件的时候,原本写的是MySQL的连接池以及hibernate的配置文件:

server.servlet.context-path=/scitc
spring.datasource.url= jdbc:mysql://localhost:3306/xxx?serverTimezone=GMT%2B8
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

但总是启动错误,错误的类型让我很是崩溃,无论百度或者其他办法,总是解决不了或许一些大神能够解决,但是我就直接放弃了,用其他的来代替:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-07-011 09:27:31.846 ERROR 6852 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
*************************** Description: Cannot determine embedded database driver class for database type NONE Action: If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

在application.yml文件中,我们可以配置阿里的druid的方法,达到相同的效果:

首先,我们要创建自己的项目(这里我是用的hibernate框架+mysql数据库,所以我就直接讲hibernate的里面怎么配置这些)。

1.在项目中引入阿里的druid的依赖:

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.0</version>
</dependency>

注意:引这些依赖的时候一定要注意一些细节问题,例如什么在前,什么应该在后。

2.之后再application.yml文件夹下面进行配置:

spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/xxx?serverTimezone=GMT%2B8
username: xxx
password: xxx
type: com.alibaba.druid.pool.DruidDataSource
jpa:
hibernate:
ddl-auto: update
show-sql: true

配置完这些,我们就要进行一个最核心的配置,这个配置是一个大佬教我的,确实好用:

在项目下面创建一个config的包,包下面创建一个类叫做DruidConfig:



在DruidConfig的类下面我们进行代码的书写:用来写入方法

@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")//这个注解非常重要,有了它,可以少配置很多东西
@Bean
public DruidDataSource dataSource () {
return new DruidDataSource();
}
}

这个配置完之后,就进入hibernate.xml文件中去,引入这个驱动:



在hibernate.cfg.xml文件里面,我们讲驱动引入:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">
<![CDATA[jdbc:mysql://localhost:3306/xxx?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT]]></property> <!--引入的驱动就是数据库的驱动-->
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<mapping class="cn.com.scitc.entity.Course"/>
<mapping class="cn.com.scitc.entity.Student"/>
<mapping class="cn.com.scitc.entity.Studentscore"/>
<!-- <property name="connection.username"/> -->
<!-- <property name="connection.password"/> --> <!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>

做好以上步骤,那么恭喜你,已经完成druid的配置。

如果大家有更好的方法,欢迎提出意见!

最新文章

  1. Objective-C中的老板是这样发通知的(Notification)
  2. IOS开发基础知识--碎片15
  3. jQuery插件(选项卡)
  4. UISegmentedControl
  5. Uva 10537 过路费
  6. LoadRunner常见问题
  7. 解决ftp连接出现 无法从控制 Socket 读取。Socket 错误 = #10054。
  8. activiti工作流数据库表详细介绍 (23张表)
  9. ext4.1动态生成多个checkboxgroup(或者radiogroup),并且有toolbar操作、
  10. A4 打印长宽
  11. css Hack 以及css的一些兼容问题小结
  12. GCC警告选项例解
  13. HDU 4746 Mophues 莫比乌斯反演
  14. MVC client validation after PartialView loaded via Ajax MVC3中 弹出 Dialog时候 提交的时候 使用 Jquery 不验证 form表单 的解决办法
  15. 《Java虚拟机原理图解》 1.2.2、Class文件里的常量池具体解释(上)
  16. xampp中mysql设置密码
  17. ListView属性解释
  18. Felx布局(三)
  19. 构建你人生里的第一个 Laravel 项目
  20. Spring源码分析 之浅谈设计模式

热门文章

  1. SQLServer 可更新订阅数据在线架构更改(增加字段)方案
  2. ASP.NET MVC 下UpdateModel可空未填写的参数为Null,为何不是空字符串
  3. 在Windows IoT上生成和识别二维码
  4. 【转】简单的jQuery插件开发方法
  5. Linux升级OpenSSL版本
  6. qtablewidget qss加上这个,QHeaderView::section
  7. Qt信号量QSemaphore(在线程里使用,结合生产者消费者的问题)
  8. 打开并锁定一个文件(使用LockFile API函数)
  9. LFS Linux From Scratch 笔记2(经验非教程)BLFS
  10. Spring特点