整合nacos时报错IClientConf that could not be found

情景

在整合nacos项目时,启动发现报错:

Bean of type 'com.netflix.client.config.IClientConfig' that could not be found

导致项目无法启动。

解决办法

在网上看到一个解决办法,新建一个类实现IClientConfig,但是别急,经过我的测试,虽然能启动了,但是在负载时并没有用,例子如下:



import java.util.Map;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import com.netflix.client.config.IClientConfig;
import com.netflix.client.config.IClientConfigKey;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;

@Component
public class RibbonConfiguration implements IClientConfig {

	@Bean
	public IRule ribbonRule(IClientConfig config) {
		// 随机算法
		return new RandomRule();
	}

	@Override
	public boolean containsProperty(IClientConfigKey arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public <T> T get(IClientConfigKey<T> arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T get(IClientConfigKey<T> arg0, T arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getClientName() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getNameSpace() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<String, Object> getProperties() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getProperty(IClientConfigKey arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object getProperty(IClientConfigKey arg0, Object arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean getPropertyAsBoolean(IClientConfigKey arg0, boolean arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int getPropertyAsInteger(IClientConfigKey arg0, int arg1) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getPropertyAsString(IClientConfigKey arg0, String arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void loadDefaultValues() {
		// TODO Auto-generated method stub

	}

	@Override
	public void loadProperties(String arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public String resolveDeploymentContextbasedVipAddresses() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> IClientConfig set(IClientConfigKey<T> arg0, T arg1) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setProperty(IClientConfigKey arg0, Object arg1) {
		// TODO Auto-generated method stub

	}
}

后来我发现 其实是版本的问题,切换一下版本就可以了,这里贴我用的版本,大家可以参考一下:

    <properties>
		<druid.version>1.0.18</druid.version>
		<jedis.version>2.9.0</jedis.version>
		<spring.version>4.3.19.RELEASE</spring.version>
		<spring-boot.version>2.2.4.RELEASE</spring-boot.version>
		<spring-cloud.version>Hoxton.SR1</spring-cloud.version>
		<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>

		<sentinel-core.version>1.7.1</sentinel-core.version>
		<spring-context-support.version>1.0.6</spring-context-support.version>

		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
		<mysql.connector.version>5.1.18</mysql.connector.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<swagger.version>2.9.2</swagger.version>

		<!-- 服务发现 -->
		<nacos-discovery.version>0.2.2.RELEASE</nacos-discovery.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>com.alibaba.csp</groupId>
			<artifactId>sentinel-core</artifactId>
			<version>${sentinel-core.version}</version>
		</dependency>

		<!-- Nacos 组件依赖 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
			<version>${nacos-discovery.version}</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba.cloud</groupId>
			<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
		</dependency>

		<dependency>
			<groupId>com.alibaba.spring</groupId>
			<artifactId>spring-context-support</artifactId>
			<version>${spring-context-support.version}</version>
		</dependency>

		<!-- swagger2 -->
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>${swagger.version}</version>
		</dependency>
	</dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-dependencies</artifactId>
				<version>${spring-boot.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

			<!-- 整合openfeign 时会用到 -->
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

			<dependency>
				<groupId>com.alibaba.cloud</groupId>
				<artifactId>spring-cloud-alibaba-dependencies</artifactId>
				<version>${spring-cloud-alibaba.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

后面整理了一个新版本的,或许对大家有点帮助。

整合SpringCloud Alibaba nacos 2.2.1_Scratch_的博客-CSDN博客

更多资源

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值