application.properties基本配置

#服务器名

spring.application.name=springBootProgram

#端口号

server.port=8093

# 数据库配置

spring.datasource.url=jdbc:oracle:thin:@ip:1521/orcl
spring.datasource.username=name
spring.datasource.password=pwd
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

#扫描mapper文件

mybatis.mapperLocations=classpath:com/data/mapper/*.xml

# kafka配置

spring.kafka.bootstrap-servers=ip:port
spring.kafka.consumer.group-id=agroup
spring.kafka.consumer.auto-offset-reset=earliest

#控制台输出执行的sql日志

logging.level.com.data.mapper=debug
#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

#设置静态资源路径

spring.thymeleaf.prefix=classpath:/templates/
spring.resources.static-locations=classpath:static/,file:static/

 

### 如何在 IntelliJ IDEA 中配置 `application.properties` 文件 #### 自动检测与添加数据源配置 IntelliJ IDEA Ultimate 版本支持根据项目中的 `application.properties` 或 `application.yaml` 文件自动检测并添加数据源配置。要启用这一功能,可以在编辑器的装订区域找到数据源图标,并单击它以完成设置[^1]。 #### 创建与编辑 `application.properties` 为了正确配置 Spring Boot 应用程序的属性文件,在 IntelliJ IDEA 中可以按照以下方式操作: 1. **创建文件** - 打开项目的资源目录(通常是 `src/main/resources`),右键点击该目录。 - 选择 `New -> File` 并命名为 `application.properties`。 2. **编写配置项** 下面是一个典型的 `application.properties` 配置示例: ```properties server.port=8081 spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=password ``` 这些配置分别设置了服务器端口、数据库连接 URL、用户名以及密码等基本信息[^2]。 3. **验证配置有效性** 利用 IDE 提供的功能检查是否存在拼写错误或者不兼容的参数组合。如果启用了 JMX 支持,则还可以进一步调整相关选项比如域名和服务名称: ```properties spring.jmx.default-domain=my.custom.domain spring.jmx.enabled=true spring.jmx.server=mbeanServerCustomName ``` 上述片段展示了如何自定义 JMX 的行为[^4]。 4. **构建自动化设置** 对于基于 Gradle 构建工具的项目来说,确保开发环境能够实时响应更改非常重要。可以通过导航至菜单栏路径 `Build, Execution, Deployment -> Gradle -> Android Compiler` 来开启 “Make project automatically”的开关[^3]。 通过上述指导,开发者能够在 IntelliJ IDEA 内部高效地管理和维护其 Spring Boot 工程所需的各类外部化配置信息。 ```java // 示例 Java 类加载 properties 文件内容 import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class AppConfig { @Value("${spring.datasource.url}") private String dbUrl; public void printDbUrl() { System.out.println("Database URL is " + dbUrl); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

郝少

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

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

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

打赏作者

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

抵扣说明:

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

余额充值