springboot+gradle配置过程中遇到的一些小坑和解决记录

编译时报错Error:java:无法访问org.apache.http.annotation.Immutable 找不到org.apache.http.annotation.Immutable的类文件 场景: 项目中使用apache http fluent发送http请求,写了一个自己的ResponseHandler来处理返回请求 public class HfiResponseHandler extends AbstractResponseHandler<String> 结果编译时报错Error:java:无法访问org.apache.http.annotation... 阅读详情

从spring转到springboot,配置过程中遇到了一些小问题,虽然都很快的解决了,还是记录一下吧,前车之鉴,以供所需。


1.gradle打包遇到错误

14:39:27.810 [INFO] [org.gradle.api.internal.tasks.compile.JdkJavaCompiler] Compiling with JDK Java compiler API.

14:39:28.033 [ERROR] [system.err] 错误: 无法访问Immutable

14:39:28.033 [ERROR] [system.err]   找不到org.apache.http.annotation.Immutable的类文件

14:39:28.033 [ERROR] [system.err] 1 个错误


原因:

httpclient:4.5.2 is not compatible with httpcore:4.4.5 because class org.apache.http.annotation.Immutable was removed from httpcore:4.4.5 and httpclient:4.5.2 still uses it!

所以,需要在dependency里面加上 4.4.4的httpcore的依赖。

compile("org.apache.httpcomponents:httpclient:4.5.2")
compile("org.apache.httpcomponents:httpcore:4.4.4")
重新编译就好了。

refer:

https://github.com/spring-projects/spring-boot/issues/6662


2.启动springboot application 报错

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

No org.slf4j.impl.StaticLoggerBinder found in ClassPath, trying with log4j2...

No org.apache.logging.log4j.Logger found found in ClassPath, trying with log4j...

No org.apache.log4j.Logger found found in ClassPath, falling back default...

原因是没有import&compile slf4j的log依赖

在dependency中添加

compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('org.slf4j:slf4j-api:1.7.21')
即可。

refer:https://github.com/bonigarcia/webdrivermanager/issues/4


3.解决了上面的问题之后,启动再次报错:

***************************

APPLICATION FAILED TO START

***************************


Description:


Configuration property name 'flowHttpConfig' is not valid:


    Invalid characters: 'H', 'C'

    Bean: payGatewayServiceImpl

    Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a letter


Action:


Modify 'flowHttpConfig' so that it conforms to the canonical names requirements.

这个原因是因为,在springboot升级到2.x.x以后,不允许configuration的property用驼峰的命名方式,要用‘-’分割。

refer:https://github.com/tobato/FastDFS_Client/issues/35


4.Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.main.banner-mode' to org.springframework.boot.Banner$Mode


原因是,yaml/yml中 ‘off’会被转为false,所以需要将配置改成:

spring:
  main:
    banner-mode: 'OFF'
原配置(错误,但是在*.properties文件中没问题):

spring:
  main:
    banner-mode: OFF
refer: https://github.com/spring-projects/spring-boot/issues/4600


5.当使用springboot时,如果依赖中添加了db数据源操作相关的,那么就要配置默认数据源,否则默认加载的时候会报错。

***************************

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 suitable jdbc url



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).


所以,解决方法:

1.配置默认数据源

2.在需要在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude
= {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。
这是因为添加了数据库组件,所以autoconfig会去读取数据源配置,而我新建的项目还没有配置数据源,所以会导致异常出现。

refer:https://blog.csdn.net/daxiang52/article/details/79420777


但是,但是,但是,敲黑板!

有同学会发现,添加了exclude之后还是报这个错误,原因是,同时引入了多个db类型的依赖,e.g. 作者同时引入了分布式数据源支持atomikos和mysql的依赖,这时候也是一直报上面的错误。

这时候,去掉一个依赖即可。去掉了atomikos之后,我的启动正常。

refer:https://stackoverflow.com/questions/49475177/failed-to-auto-configure-a-datasource-spring-datasource-url-is-not-specified

冲突的包可能不尽相同,检查方向对了就好。

cannot access org.apache.http.annotation.Immutable 现象: [ERROR] diagnostic: error: cannot access org.apache.http.annotation.Immutable class file for org.apache.http.annotation.Immutable not found 分析: 预计是兼容性问题 具体见:https://github.com/spring-proj... 阅读详情

相关推荐

Error:java: 无法访问org.apache.http.annotation.ThreadSafe 找不到org.apache.http.annotation.ThreadSafe的类文件

这几天需要把项目升级,项目用的是springboot,由1.X升级为2.X,这个过程中很是煎熬,各种报错,于是就重新创建新的2.X的项目,然后,再将原来项目的内容迁移过去,但是在这个过程中,出现了一个问题,正如文章标题所写的,有个ThreadSafe找不到。因为项目中依赖了org.apache.http.annotation下的httpclient(v4.5)core(v4.4.6)。...

jfqqqqq的博客 1万+

配置cursor进行Java springboot项目开发

配置ai开发工具cursor ide的java开发环境

程序员记事本 3万+

spring boot 启动报错:Reason: Canonical names should be kebab-case ('-' separated), lowercase

spring boot 1.x 切换 2.x 以后启动报如下错误: *************************** APPLICATION FAILED TO START *************************** Description: Configuration property name 'sysConf' is not valid: Invalid ...

兴趣是最好的老师,勤能补拙 1万+

支付宝接口学习踩坑记(2)——基于SpringBoot的Alipay-EasySDK配置及网页支付接口简单示例

网上直接搜索Alipay-EasySDK出来的都是老版SDK的配置方案,所以接触新版SDK(Alipay-EasySDK)时踩了很多坑。在这里总结成一篇笔记。利用了Spring Boot的特性,在应用启动时就填装SDK需要的密钥、APPID等信息。并附有简单的演示代码。如果代码有误无法运行,或者有其他问题,可以在下面评论告诉我

JikeStardy的博客 5504

使用gradle构建spring cloud,搭建一个cloud的helloworld

spring cloud 越来越流行了,当初学习的时候都是使用maven构建的cloud(网上很多的springcloud案例也是通过maven构建的,gradle构建的cloud资料很少,或者说不全面),所以我一直想使用gradle构建一个cloud的demo.上周花了一个晚上整了一个demo,今天找个时间写一篇博客记录下… 直入主题>>>>>> 使用的版本如下: springBootVersion = '2.0.1.RELEASE' springCloudVers.

web13985085406的博客 723

Spring Boot 2.1.2 & Spring Cloud Greenwich 升级记录

节前没有新业务代码,正好Greenwich刚发布,于是开始为期四天的框架代码升级。 之前的版本是 spring boot 1.5.10 , spring cloud Edgware.SR3 依赖升级 增加依赖管理插件 apply plugin: 'io.spring.dependency-management' spring-clou...

weixin_34024034的博客 391

工作中bug以及问题解决笔记

teams查询条件的值中不能有大写字母,会匹配不到值,在创建index对应的mapping的某个field时,如果mapping没有指定该field的标准化配置normalizer,如果写入ES的时候是大写,则搜索出来的结果也是大写的。Redis命令可能会执行失败,仅仅是由于错误的语法被调用(命令排队时检测不出来的错误),或者使用错误的数据类型操作某个Key: 这意味着,实际上失败的命令都是编程错误造成的,都是开发中能够被检测出来的,生产环境中不应该存在。事实上该依赖理论上可以参与编译,测试,运行等周期。

qq_28390933的博客 741

java restful接口开发实例_使用Kotlin搭配Springboot开发RESTFul接口

哈喽,好久不见,看了一眼推送记录,我已经差不多一个月没发文章了,忙->累->懒,所以一直没写,最近答辩结束了,也终于可以抽出时间分享点最近学的东西~关于kotlin去年还是前年谷歌为kotlin背书的时候我就注意到这个语言了,还给团队买了好几本kotlin的书,总之我是比较看好这个语言的发展的,不过一直没有上手用过,这次就拿kotlinspringboot框架来试试水,期待kotli...

weixin_39537977的博客 328

@SpringBootTest 单元测试遇到的坑

spring boot测试类包名与main下application.class启动类的包名默认要一致 今天在做数据库连接单元测试测时候发现,jdbcTemplate自动注入不进去提示 Could not autowire. No beans of 'JdbcTemplate' type found 运行测试单元报错提示如下: 后来折腾了半天,发现是因为单元测试的路径main下a...

痞子的博客 7991

Configuration property name ‘fdfs.thumbImage‘ is not valid

参考fastDFS官方文档:https://github.com/tobato/FastDFS_Client SpringBoot 2.0 以后使用FastDFS会这个错误: Invalid characters: 'I' Bean: defaultThumbImageConfig Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must sta..

ForestCat的专栏 1028

spring boot启动报错:Reason: Canonical names should be kebab-case (‘-‘ separated), lowercase

spring boot启动之后报错: Description: Configuration property name 'dataSource' is not valid: Invalid characters: 'S' Bean: myDateSource Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start

xiaoning9299的博客 6466

找不到org.apache.http.annotation.NotThreadSafe的类文件

找不到org.apache.http.annotation.NotThreadSafe的类文件

ideal-lingyun 713

05、SpringBoot开发实用篇

什么是热部署?简单说就是你程序改了,现在要重新启动服务器,嫌麻烦?不用重启,服务器会自己悄悄的把更新后的程序给重新加载一遍,这就是热部署。热部署的功能是如何实现的呢?这就要分两种情况来说了,非springboot工程springboot工程的热部署实现方式完全不一样。先说一下原始的非springboot项目是如何实现热部署的。非springboot项目热部署实现原理开发非springboot项目时,我们要制作一个web工程并通过tomcat启动,通常需要先安装tomcat服务器到磁盘中,开发的程序配置发布

... 1256

无法访问org.apache.http.annotation.ThreadSafe 找不到org.apache.http.annotation.ThreadSafe的类文件

明天更新

风雨诗轩的博客 6073
上一篇: springboot 2.0+mybatis+hikari/druid+atlas+mysql 配置多数据源及遇到的坑
下一篇: Unicode、UTF-8、ASCII等编码方式浅述
michaelgo
博客等级 码龄16年 36粉丝 20原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值