最近实践踩坑日记

问题1:别人dubbo总是调不通我的服务

org.apache.dubbo.remoting.RemotingException: client(url: dubbo://192.168.56.1:28085/com.alibaba.cloud.dubbo.service.DubboMetadataService?actives=100&anyhost=true&application=seckill-service&bind.ip=192.168.56.1&bind.port=28085&check=false&codec=dubbo&connect.lazy.initial.state=true&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&group=cart-service&heartbeat=60000&interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&pid=23444&qos.enable=false&register.ip=192.168.8.102&release=2.7.12&remote.application=cart-service&revision=2.2.7.RELEASE&router=-default,revisionRouter&sca_revision=4F663C449502A050C7216B07EE4866D5&send.reconnect=true&service.name=ServiceBean:cart-service/com.alibaba.cloud.dubbo.service.DubboMetadataService:1.0.0&side=consumer&sticky=false&timeout=5000&timestamp=1690978959234&version=1.0.0) failed to connect to server /192.168.56.1:28085 client-side timeout 3000ms (elapsed: 3002ms) from netty client 192.168.8.102 using dubbo version 2.7.12
        at org.apache.dubbo.remoting.transport.netty4.NettyClient.doConnect(NettyClient.java:174)
        at org.apache.dubbo.remoting.transport.AbstractClient.connect(AbstractClient.java:198)
        at org.apache.dubbo.remoting.transport.AbstractClient.<init>(AbstractClient.java:73)
        at org.apache.dubbo.remoting.transport.netty4.NettyClient.<init>(NettyClient.java:82)

然后我cmd,ipconfig,有2个网卡
在这里插入图片描述
查看Nacos的配置
在这里插入图片描述
在这里插入图片描述

问题2:Dubbo调用报找不到该类或者方法

一般从2个方面入手,配置和对方的实体类是否实现了序列化Serializable
配置:

dubbo:
  scan:
    base-packages: com.fh.shopping
  protocol:
    name: dubbo
    port: 28090
  consumer:
    check: false
    timeout: 5000
  provider:
    threads: 200
    actives: 100
#  特别是这个地方【服务消费方 是否没有订阅 服务提供方】
  cloud:
    subscribed-services: base-service

问题3:用LocalDateTime做日期,用ShardingSphere做分表分库策略

报错如下:一直说我这个字段拿不到

{"@timestamp":"2023-10-11T10:54:09.825+08:00","level":"ERROR","thread":"http-nio-18080-exec-10","class":"com.marketing.plat.common.web.handler.
GlobalExceptionHandler","function":"handle","line":"41","tid":"1190cc8a63b44851858cc9acf8db3f1a.102.16969928498083813","uid":"1701506916987240449","orderNo":"",
"message":"[ 系统未知错误 ] org.springframework.dao.InvalidDataAccessApiUsageException: Error attempting to get column 'activity_start_time' from result set.  
Cause: java.sql.SQLFeatureNotSupportedException: getObject with type\u2028; getObject with type; nested exception is java.sql.SQLFeatureNotSupportedException: 
getObject with type\u2028\tat org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:96)\u2028Caused 
by: java.sql.SQLFeatureNotSupportedException: getObject with type\u2028\tat org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.
AbstractUnsupportedOperationResultSet.getObject(AbstractUnsupportedOperationResultSet.java:221)\u2028"}

心路历程:测试和本地都行,上到生产就不行呢???
实则不然,就是自己配置忘记了

dubbo:
  scan:
    base-packages: com.fh.shopping
  protocol:
    name: dubbo
    port: 28090
  consumer:
    check: false
    timeout: 5000
  provider:
    threads: 200
    actives: 100
   # 重要的就是这个配置
  cloud:
    subscribed-services: base-service

附赠Local DATe Time转化的策略

import cn.hutool.core.date.DatePattern;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@MappedTypes(LocalDateTime.class)
public class CustomLocalDateTimeTypeHandler extends BaseTypeHandler<LocalDateTime> {
    private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN);

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, LocalDateTime parameter, JdbcType jdbcType)
            throws SQLException {
        if (parameter != null) {
            ps.setString(i, dateTimeFormatter.format(parameter));
        }
    }

    @Override
    public LocalDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String target = rs.getString(columnName);
        if (StringUtils.isEmpty(target)) {
            return null;
        }
        return LocalDateTime.parse(target, dateTimeFormatter);
    }

    @Override
    public LocalDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String target = rs.getString(columnIndex);
        if (StringUtil.isEmpty(target)) {
            return null;
        }
        return LocalDateTime.parse(target, dateTimeFormatter);
    }

    @Override
    public LocalDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String target = cs.getString(columnIndex);
        if (StringUtil.isEmpty(target)) {
            return null;
        }
        return LocalDateTime.parse(target, dateTimeFormatter);
    }
}

字符串拼接sql

update shopping_cart_22 set image_url_org = CONCAT(image_url_org ,‘?x-oss-process=image/resize,h_100,m_lfit’) where user_id = 1693459306401861634;

问题4:HTTP调用外部系统报连接拒绝,马上再请求一次就ok了,隔很长一段时间就会出现

http调用XX报错,org.apache.http.conn.HttpHostConnectException: Connect to 124.232.138.162:9900[/124.232.138.162] failed: Connection refused (Connection refused)

还在找原因!!!
谨以此文记录,愿我能从容!!!
可怜身上衣正单,心忧炭贱愿天寒。

### 解决方案 当遇到 `No spring.config.import property has been defined` 的错误时,通常是因为 Spring Boot 配置文件未能正确加载外部配置源。以下是可能的原因以及解决方案: #### 1. **确认是否启用了 Config Client 功能** 如果项目依赖于 Spring Cloud Config Server,则需要确保客户端已正确定义了 `spring.config.import` 属性来指向 Config Server[^2]。可以在 `application.properties` 或 `application.yml` 文件中添加如下内容: ```properties spring.config.import=optional:configserver:http://localhost:8061/ ``` 此设置表示应用程序会尝试从指定的 Config Server 加载配置。如果无法连接到服务器,由于使用了 `optional:` 前缀,程序仍可正常启动。 --- #### 2. **检查 Spring Boot 版本兼容性** 不同版本的 Spring Boot 对 `spring.config.import` 的支持有所不同。根据提供的引用表[^3],建议升级至至少 Spring Boot 2.3.x 及以上版本,因为该功能是在这些版本中引入并完善的。可以通过修改项目的 `pom.xml` 来更新依赖项: ```xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.2.RELEASE</version> </parent> ``` --- #### 3. **验证配置文件路径与名称** 默认情况下,Spring Boot 使用名为 `application.properties` 或 `application.yml` 的文件作为主要配置来源。如果自定义了其他配置文件名或位置,则需通过 JVM 参数显式声明其路径。例如,在运行命令中加入以下选项: ```bash java -Dspring.config.location=./custom-config/ -jar app.jar ``` 或者直接在配置文件中补充额外导入规则: ```yaml spring: config: import: classpath:/additional-configs/,file:///external-folder/ ``` --- #### 4. **激活正确的 Profile** 某些场景下,特定环境变量仅适用于某个活动 Profile。因此,请确保设置了合适的活跃 Profile 并包含了必要的属性定义。例如,可以传递命令行参数启用 Native 模式的 File System 后端服务[^2]: ```bash java -Dspring.profiles.active=native -jar app.jar --spring.config.import=configtree:/etc/config/ ``` --- #### 5. **排查 Stream Listener 注解冲突** 虽然当前问题看似无关紧要,但如果涉及复杂的事件驱动架构(如 Kafka Streams),则可能存在隐含关联。回顾相关组件逻辑以排除潜在干扰因素[^4]。具体而言,应关注是否存在重复监听器注册或其他竞争条件影响初始化过程的行为模式。 --- ### 总结代码片段 最终调整后的核心部分可能类似于这样: ```java @SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); } } ``` 伴随对应的资源配置示例: ```yaml spring: profiles: active: native cloud: config: uri: http://localhost:8061/ config: import: optional:configserver:${SPRING_CONFIG_SERVER_URI},classpath:/default-settings/ server: port: 8080 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值