HoneyMoose
  • 首页
  • Java
  • Jersey
  • Jira
  • Confluence
  • U.S.
    • USRealEstate
    • USVisaTrack
    • H1B
  • 项目和网站
    • CWIKI.US
    • OSSEZ 社区
    • WIKI.OSSEZ.COM
    • BUG.OSSEZ.COM
    • RSS.OSSEZ.COM
Spring
Spring

Spring boot 启动提示数据源错误

在启动 Spring Boot 的项目的时候提示数据源未配置的错误。 09:52:08.333 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exception org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:233) at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:174) Spring 会提示你完整的导致启动错误的信息是: *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active). Process finished with exit code 1 错误分析 从上面的启动信息来看,已经说得非常清楚了,就是因为你配置了 Spring 的数据组件,但是你没有配置相应的数据源。 因为这个会导致你的启动失败。 解决办法 有下面的集中解决办法: 加入 H2 包 最简单的解决办法就是在依赖中添加 H2 的数据库,如果你使用 Spring Batch 的话,这个组件也是需要的,因为 Spring 会使用 H2 为数据源。 添加数据源配置 如果你已经添加了数据库驱动,例如你添加了 mysql 的数据库驱动。 那么你需要制定 Mysql 的数据库连接参数。 spring.datasource.url=jdbc:mysql://localhost:3306/myDb spring.datasource.username=user1 spring.datasource.password=pass spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 在启动时候不载入数据源配置。 你可用在启动的时候不载入数据源配置。 可用在启动类上面,添加下面的注解。 @SpringBootApplication(exclude={DataSourceAutoConfiguration.class})     你也可以在启动配置文件上面,添加下面的内容,这样能够保证你在启动的时候不载入数据源配置类。 spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAuto   https://www.ossez.com/t/spring-boot/504

2020年09月21日 0Comments 1524Browse 2Like Read more
Spring

Srping RestTemplate 将 Web 上的 JSON 数据快速本地实例化

在很多平常的数据收集和挖掘过程中,我们可能希望将网络上的 JSON 数据库快速获取并且插入到本地数据库中。 通常方法就是将 JSON 数据下载,然后对 JSON 数据库进行处理,然后保存。 Spring 有没有提供什么快速的方法进行处理?     其实 Spring 提供了一个 RestTemplate 可以完成数据下载,并且进行在内存中进行对象的转换。 有关 RestTemplate 的 API ,你可以参考 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html 中的内容。 这里我们使用的是 exchange 进行的转换。 例如, 我们希望将 https://covidtracking.com/api/v1/states/current.json 中的数据存入到我们的本地数据库中。 我们就可以使用提供的 exchange 方法。 首先我们需要定义:Covid19Current 对象,这个对象必要重要,首先这个对象是 JPA 的对象,同时这个对象也映射了 JSON 数据中的字段。 如果你不希望这样映射的话,那么你需要进行字段的转换。 请参考 :https://github.com/ossez-com/covid-19/blob/master/covid-19-common/src/main/java/com/ossez/covid19/common/models/Covid19Current.java 文件中,我们定义的字段内容。 然后你就可以使用下面的代码进行数据转换和映射: ResponseEntity<Covid19Current[]> responseEntity = restTemplate.exchange("https://covidtracking.com/api/v1/states/current.json", HttpMethod.GET, null, Covid19Current[].class); Covid19Current[] covid19Currents = responseEntity.getBody(); 请注意,我们这里使用的 Get 方法,然后将数据转换到对象 Array 中。 具体方法,请参考:https://github.com/ossez-com/covid-19/blob/master/covid-19-service/src/main/java/com/ossez/covid19/service/batch/tasklet/Covid19Tasklet.java   https://www.cwiki.us/display/SpringBootZH/questions/57939087

2020年04月16日 0Comments 576Browse 0Like Read more
Spring

@ComponentScan 无参数

Spring @ComponentScan 无参数的组件扫描路径是什么 在 Spring 中,我们使用 @ComponentScan 和 @Configuration 注解来指定希望扫描的 Package。 如果你使用的 @ComponentScan 的话,将会扫描当前文件夹和所有的子文件夹。 https://www.cwiki.us/display/SpringBootZH/questions/57939056

2020年04月14日 0Comments 1077Browse 0Like Read more
Spring

Srping Batch 不能 autowire. No beans of 'JobBuilderFactory' type found

Spring Batch 在 autowire 的时候提示: Could not autowire. No beans of 'JobBuilderFactory' type found. 这个错误提示其实是在 IntelliJ 中提示的,尽管有这个错误,你的程序还是可以运行没有问题的。   简单来说,这个提示就是 IntelliJ 没有办法通过 Autowire 找到对应的 Bean。 如果你使用的是 Spring Batch 的话,你可以在你的 Batch 配置文件中添加: @EnableBatchProcessing 注解。 这样的话,你的Class 就不会在 IntelliJ 中有这个错误提示了。   https://www.cwiki.us/display/SpringBatchZH/questions/57939048

2020年04月14日 0Comments 996Browse 0Like Read more
Spring

@Controller 和 @RestController 区别是什么

@RestController 在 Spring MVC 中就是 @Controller 和 @ResponseBody 注解的集合。 @RestController 注解是从 Spring 4.0 版本开始添加进来的,主要用于更加方便的构建 RESTful Web 服务。 @ResponseBody 该注解用于将Controller的方法返回的对象,通过适当的HttpMessageConverter转换为指定格式后,写入到Response对象的body数据区。使用此注解此次请求将不再走视图处理器,而是直接将此响应结果写入到输入流中,其效果等同于使用response对象输出指定格式的数据。 在 RESTful 的服务中,我们大部分情况是使用 JSON 为返回数据的,所以你可以直接使用  @RestController 替换掉 @Controller 和 @ResponseBody。 根据上面的解释,下面的 2 段代码是完全一样的: @Controller @ResponseBody public class MVCController { .. your logic } @RestController public class RestFulController { .... your logic }   https://www.cwiki.us/display/SpringBootZH/questions/57939042

2020年04月14日 0Comments 748Browse 0Like Read more
Spring

Spring Boot 项目编译时提示错误 cannot access WebApplicationInitializer 错误

具体的提示信息如下: Error:(21, 8) java: cannot access org.springframework.web.WebApplicationInitializer class file for org.springframework.web.WebApplicationInitializer not found   这个错误要结合你的 Application 代码来看。 因为在 Application 的代码中,我们继承了 SpringBootServletInitializer。 请注意:我们定义的 Application: public class Application extends SpringBootServletInitializer{ } 正是因为这个定义,所以你的 POM 或者 build.gradle 中 需要添加:spring-boot-starter-web 依赖。 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.2.6.RELEASE</version> </dependency> 然后你再次编译的项目,你就不会有提示编译错误了。 https://www.cwiki.us/display/SpringBootZH/questions/57939020

2020年04月13日 0Comments 735Browse 0Like Read more
Spring

Spring Boot 使用 H2 数据库的控制台(Console)

如果你希望在 Spring Boot 启用 H2 数据库的话,这篇文章适合你进行了解。 概述 在这个指南中,我们将会考虑如何在  Spring Boot 中使用 H2 数据库。 与其他数据库相似,Spring Boot 生态系统中能够完全支持 H2 数据库 依赖(Dependencies) 让我们首先需要定义 H2 数据库依赖:https://search.maven.org/search?q=g:com.h2database 同时我们还需要使用 spring-boot-starter-data-jpa 依赖:https://search.maven.org/search?q=a:spring-boot-starter-data-jpa <dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-data-jpa</artifactId>     <version>2.1.4.RELEASE</version> </dependency> <dependency>     <groupId>com.h2database</groupId>     <artifactId>h2</artifactId>     <scope>runtime</scope>     <version>1.4.199</version> </dependency> 与其他的 Spring Boot 管理相似,通常你不需要为你使用的 Spring Boot 指定版本号。 数据库配置 在默认的情况下,Spring Boot 将会配置 H2 数据库使用 sa 为用户名,用户名密码为空。 当然你可以可以通过修改 application.properties  文件中配置文件来为你的 H2 数据库指定登录的用户名和密码。 spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=password spring.jpa.database-platform=org.hibernate.dialect.H2Dialect 如果你使用的 H2 基于内存的数据库的话,你所有存储在内存中的数据将会在你重新启动服务器的时候完全丢失。 如果你希望避免这个情况的话,你可以使用基于文件存储的数据库,你可以通过下面的参数修改为基于文件使用的数据库,修改 spring.datasource.url: 参数为 spring.datasource.url=jdbc:h2:file:/data/demo 文件系统使用的路径为绝对路径,有关 H2 数据库配置的方法,请参考 http://www.h2database.com/html/features.html#connection_modes 页面中的内容。 数据库选项 Spring Boot 整合 H2 提供的增删改查(CRUD)与普通数据库的增删改查是相似的。请参考 https://www.baeldung.com/persistence-with-spring-series 页面中获得更多的有关数据持久化相关的信息。 在这里,请将 data.sql 文件添加到 src/main/resources 目录下面: DROP TABLE IF EXISTS billionaires;   CREATE TABLE billionaires (   id INT AUTO_INCREMENT  PRIMARY KEY,   first_name VARCHAR(250) NOT NULL,   last_name VARCHAR(250) NOT NULL,   career VARCHAR(250) DEFAULT NULL );   INSERT INTO billionaires (first_name, last_name, career) VALUES   ('Aliko', 'Dangote', 'Billionaire Industrialist'),   ('Bill', 'Gates', 'Billionaire Tech Entrepreneur'),   ('Folrunsho', 'Alakija', 'Billionaire Oil Magnate'); Spring Boot 将会在系统应用程序启动后,将会自动选择  data.sql 文件然后在我们的 H2 数据库中进行配置。 这种方式是对使用的数据库进行进行测试的比较好的办法。 访问 H2 控制台 H2 数据库有一个嵌入式 GUI 控制台能够让你对数据库的内容进行查询和运行  SQL。 在默认情况下,H2 的控制台没有嵌入到 Spring 中。所以你需要对这个控制台工具进行启用,请在 application.properties 文件中添加下面的参数: spring.h2.console.enabled=true 在启用上面的参数后,如果你启用了 Spring Boot 应用程序,你可以导航到 http://localhost:8080/h2-console界面中,在这个界面中首先将会显示登录界面。 在登录界面中适用的登录信息是你在 application.properties 文件中指定的登录信息。 一旦你成功连接到控制台后,我们将会看到一个完整的控制台界面。 在这个完整的控制台界面中的作出,你将会看到 H2 数据库中所有的数据表,同时还包含有一个文本对话框中包含了可以运行的 SQL 查询: 在这个 Web 的控制台界面中,具有自动完成 SQL 关键字的功能。这个功能能够让给控制台更加轻量的运行并且具有 SQL 关键字帮助的功能,能够让你在文本对话框中直接运行 SQL 脚本。 更进一步,我们将会在 application.properties 中配置更多的参数能够满足你的对当前项目的需求: spring.h2.console.path=/h2-console spring.h2.console.settings.trace=false spring.h2.console.settings.web-allow-others=false 在上面的代码中,我们设置了 H2 的控制台访问控制台的 URL 为: /h2-console,这个链接是针对你当前项目运行的服务器地址和端口的相对地址。 例如你当前服务器运行的 URL 为  http://localhost:9001 那么 H2 控制台访问的地址为  http://localhost:9001/h2-console。 同时我们设置了 spring.h2.console.settings.trace 参数为 false,这样我们能够避免在系统控制台中输出 trace 级别的日志信息。 通过设置 spring.h2.console.settings.web-allow-others=false 参数,我们能够禁止远程 Web 访问 H2 数据库的信息。 结论 H2 是完全与 Spring Boot 兼容的,通过这篇文章,你能够了解如何使用 H2 控制台来管理整治运行的数据库。 有关完整的代码情况参考我们提交到 GitHub 中的代码示例:https://github.com/cwiki-us-demo/java-tutorials/tree/master/persistence-modules/spring-boot-persistence-h2-console 中的内容。 LikeBe the first to like this

2020年04月04日 0Comments 466Browse 0Like Read more
Spring

Spring Boot 中如何启用 H2 的控制台

如何在 Spring Boot 中如何启用 H2 的控制台? 你需要在你的 application.properties 文件中启用配置: spring.h2.console.enabled=true spring.h2.console.path=/h2-console 具体的配置你可以参考页面 Spring Boot 使用 H2 数据库的控制台(Console) 中的内容。 运行后的界面如下: 使用的端口,是你 Spring Boot 运行使用的端口。 登录进去数据库后查看的界面: 你也可以访问 GitHub 上面的内容下载代码: https://github.com/cwiki-us-demo/java-tutorials/tree/master/persistence-modules/spring-boot-persistence-h2-console 有关本内容的链接: https://www.cwiki.us/display/SpringBootZH/questions/57938823  

2020年04月04日 0Comments 620Browse 0Like Read more
Spring

Spring Boot 使用 spring.datasource.data 的时候找不到数据文件

对需要导入使用 SQL 文件,已经放置到了 resources\data-trans.sql 下面了。 但是在配置的时候配置: spring.datasource.data=data-trans.sql 显示这个数据库 SQL 文件找不到。 错误的信息为: Property spring.datasource.data with value 'ServletContext resource [/data-trans.sql]' is invalid: The specified resource does not exist. 你需要将 spring.datasource.data=data-trans.sql 的文件路径配置参数修改为: spring.datasource.data=classpath:data-trans.sql 或 spring.datasource.data=classpath:/data-trans.sql 都可以,这个主要告诉 Spring Boot 载入数据文件的路径。 https://www.cwiki.us/display/SpringBootZH/questions/57938806

2020年04月04日 0Comments 4179Browse 0Like Read more
Spring

Spring Boot 如何以 Web 应用的方式启动

在 Spring Boot 启动的时候,在进程完成后会自动退出。 如何让 Spring Boot 以 Web 方式启动,并且进程不退出呢? 需要确定下 Web 的这个依赖是否在你的依赖中。 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 如果没有的话,你需要讲上面的依赖添加到你的项目中。   然后再重新启动后,你会发现你的 Web 应用没有在完成后自动退出了。 https://www.cwiki.us/display/SpringBootZH/questions/57938770  

2020年04月04日 0Comments 666Browse 0Like Read more
12345
Newest Hotspots Random
Newest Hotspots Random
ChatGPT 的 API 调用可不太便宜 来看一个 ChatGPT 有关程序员的笑话 IntelliJ IDEA 的 Code Coverage 测试 Okhttp 如何构建一个 Get 的 URL SpringBoot 使用 @ConfigurationProperties 异常 Not registered via @EnableConfigurationProperties Jackson 的 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
说说这 48 小时核酸检测的时间FAA 真的应该换换系统了Java 8 使用 Stream 把 List 转换为 mapPowerShell 中运行 maven 参数无法识别1月14号的 UA857Jackson 的 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
A “word-wrap” functionality(一个字符串包裹函数) Confluence 6 连接一个 LDAP 目录概述 Discourse 如何限制注册用户的密码长度 Confluence 6 修改站点的标识图片 Confluence 6 空间标识 微信小程序的 AppID 到哪里找
Categories
  • Algorithm(算法)
  • AMQP
  • Angular
  • CI
  • Compile And CI
  • Computer Science
  • Confluence
  • DataBase
  • Gradle
  • H1B
  • Hibernate
  • IDE
  • Java
  • Jersey
  • Jira
  • MariaDB
  • PrestaShop
  • Spring
  • Spring Batch
  • U.S.
  • USRealEstate
  • USVisaTrack
  • 我的小厨

COPYRIGHT © 2020 HoneyMoose. ALL RIGHTS RESERVED.

THEME CWIKIUS.CN MADE BY VTROIS