java开发问题及解决方案

重要提示:此文章将持续更新,建议收藏


1、java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR

原因: 使用tomcat7调整协议从http到https后,启动tomcat时报的错,原本protocol写的是HTTP/1.1
解决: tomcat7默认使用的是APR协议,更改8443端口的protocol协议为org.apache.coyote.http11.Http11Protocol

修改conf/server.xml

    <Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
    disableUploadTimeout="true" enableLookups="false" maxThreads="150"
    port="8443" keystoreFile="D:\java_code\tomcat\tomcat.keystore" keystorePass="1q2w3e4r"
    protocol="org.apache.coyote.http11.Http11Protocol" scheme="https"
    secure="true" sslProtocol="TLS" />

2、org.hibernate.InstantiationException: No default constructor for entity: : com.su.shoppingb.domain.Cart

解决: Cart实体类没有默认的构造方法,添加上即可


3、java.nio.charset.MalformedInputException: Input length = 1 或者java.nio.charset.MalformedInputException: Input length = 2

解决: application.yml中 编码格式问题,重设为GBK即可;整个项目是UTF-8

mybatis: mapper-locations: classpath:/mappers/*.xml 填写完整


4、在mapper.xml中,resultType指向实体类,select出的结果别名要和实体类字段一样


5、Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)

解决: 无关紧要不理会,或者在templates目录下添加文件即可解决


6、保存用户时,java.sql.SQLSyntaxErrorException: Table ‘wx_driving.hibernate_sequence’ doesn’t exist

解决: 在该实体类的主键上加上
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)


7、微信小程序前端获取手机号信息时,“getPhoneNumber:fail Error: 该 appid 没有权限”

解决: 小程序号需要企业注册小程序并认证


8、HikariPool-1 - Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@7bd3fbc (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

解决:
在application.xml中添加spring.datasource.hikari
hikari:
connection-timeout: 60000
validation-timeout: 3000
idle-timeout: 60000
login-timeout: 5
max-lifetime: 60000
maximum-pool-size: 10
minimum-idle: 10
read-only: false
添加连接生命周期


9、后端服务换了新的appid后,获取openid出现 {“errcode”:40029,“errmsg”:“invalid code, hints: [ req_id: 0Hga3aMre- ]”}

解决: 前端和后端统一使用新的appid和appsecret


11、获取手机号时,调接口:org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter ‘encryptedData’ is not present

解决: 前端请求加: header: {
“Content-Type”: “application/x-www-form-urlencoded”
},


12、java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/CBC/PKCS7Padding

解决: AES/CBC/PKCS7Padding改成AES/CBC/PKCS5Padding


13、启用https org.springframework.context.ApplicationContextException: Failed to start bean ‘webServerStartStop’; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server

解决: springboot2.x没有EmbeddedServletContainerFactory,已替换为TomcatServletWebServerFactory 添加以下代码:

@Bean
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
    return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
        @Override
        public void customize(ConfigurableWebServerFactory factory) {
            factory.setPort(443);
        }
    };
}
/**
* @Description:  将http重定向至https
* @param: "[]"
* @Return: org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
* @Author: supenghui
* @Date: 2021/1/18 12:46
*/
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(){
    TomcatServletWebServerFactory tomcat =new TomcatServletWebServerFactory(){
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint=new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection=new SecurityCollection();
            collection.addPattern("/");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(createHttpConnector());
    return tomcat;
}
private Connector createHttpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setSecure(false);
    connector.setPort(80);
    connector.setRedirectPort(443);
    return connector;
}

14、测试微信小程序使用高德地图出现 fail url not in domain list

解决: 使用高德地图服务,需要把高的域名加到request中;域名: https://restapi.amap.com


15、各种图案的样式:https://css-tricks.com/the-shapes-of-css/


16、org.springframework.dao.InvalidDataAccessApiUsageException: No EntityManager with actual transaction available for current thread - cannot reliably process ‘remove’ call; nested exception is javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process ‘remove’ call

解决: 由于在需要事务的方法上,没有开启事务,所在在方法上添加@Transactional


17、Error No.1130 Host ‘192.168.25.3’ is not allowed to connect to this MySQL server

解决:

  1. 改表法
    可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑登入MySQL后,更改"MySQL"数据库"user"表里的"host"项,将"localhost"改成"%"
    mysql -u root -pyourpwd
    mysql>use mysql;
    mysql>update user set host = ‘%’ where user =‘root’;
    mysql>select host, user from user;

18、调用微信支付接口时,total_fee必须为Integer


19、解决feign.RetryableException: Read timed out/java.net.SocketTimeoutException: Read timed out

application.yml中添加以下配置:

#更改连接和读取超时时间
feign:
  client:
    config:
      default:
        connectTimeout: 300000
        readTimeout: 300000

20、解决c.netflix.discovery.TimedSupervisorTask : task supervisor timed out

原因分析

项目启动初始化时,会启动两个定时任务,一个是向eureka注册,即心跳的线程,另一个是从eureka获取服务注册列表,即刷新注册列表缓存的线程,上述两个线程都是每30s执行一次,默认超时时间都为30s,所以当30s未执行完该任务是,便会抛出Timeout的异常。发送心跳的任务比较简单,一般不会超时。而获取注册列表的任务,耗时较久。
解决:
由于注册中心是所有服务通信的基础,所以部署在多个服务器的应用在通信时可能会比较耗时,往往会发生超时。

application.yml中添加以下配置:

eureka:
  client:
    registry-fetch-interval-seconds: 30  #更改注册表获取间隔时间

author:su1573
鄙人记录生活点滴,学习并分享,请多指教!!!
如需交流,请联系 sph1573@163.com,鄙人看到会及时回复

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ssy03092919

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值