To use only local configuration in your Spring Boot application

To use only local configuration in your Spring Boot application and avoid fetching configuration from a Nacos server, you can adjust your application settings to disable Nacos configuration fetching. Here's how you can configure it:


1. Exclude Nacos Config in Dependencies

If you're using spring-cloud-starter-alibaba-nacos-config, remove it from your pom.xml or build.gradle. This ensures the application doesn't fetch configurations from Nacos.

For example, in Maven:

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


2. Disable Nacos Config Fetching

If you need to keep the dependency (e.g., for service discovery), explicitly disable the Nacos configuration fetching by setting the following properties in application.yml or application.properties:

spring: cloud: nacos: config: enabled: false

This configuration disables the Nacos configuration feature while allowing other Nacos functionalities like service discovery.


3. Use Only Local Configurations

Ensure your local configurations are defined in application.yml or application.properties. For example:

server: port: 8080 app: name: LocalConfigApp datasource: url: jdbc:mysql://localhost:3306/mydb username: root password: password


4. Explicitly Set Profile (Optional)

If your application has multiple environments, set the active profile explicitly to use local configurations:

spring: profiles: active: local

And create an environment-specific configuration file such as application-local.yml:

app: environment: local


5. Verify at Startup

When you start your application, check the logs to ensure that it is not fetching any configuration from Nacos.

Look for:

  • No attempts to connect to Nacos (NacosPropertySource logs).
  • Only local configuration being loaded.

6. (Optional) Remove Nacos Config Beans

If the above methods still cause Nacos config to interfere, you can explicitly exclude the related auto-configuration classes:

@SpringBootApplication(exclude = { NacosConfigBootstrapConfiguration.class }) public class LocalConfigApplication { public static void main(String[] args) { SpringApplication.run(LocalConfigApplication.class, args); } }

相关推荐
IT_陈寒2 分钟前
Vite的public文件夹放静态资源?这坑我替你踩了
前端·人工智能·后端
浮游本尊3 分钟前
合同同步逻辑
后端
子兮曰22 分钟前
别让爬虫白嫖你的导航站了:纯免费,手把手实现加密字体防爬
前端·javascript·后端
阿苟28 分钟前
JAVA重点难点
后端
uzong37 分钟前
TIOBE 指数:2026 年编程语言排行榜
后端
ja哇38 分钟前
大厂面试高频八股
java·面试·职场和发展
小村儿44 分钟前
连载06 - Hooks 源码深度解析:Claude Code 的确定性自动化体系
前端·后端·ai编程
用户8356290780511 小时前
使用 Python 设置 Excel 数据验证
后端·python
yoyo_zzm1 小时前
Laravel6.x新特性全解析
java·spring boot·后端
xiaobaoyu1 小时前
ssm
后端