Log4j配置文件位置+Spring数据源配置文件位置

一个.Log4j配置文件位置

1.加载自己主动

当应用程序启动,缺省情况下,这将是src文件夹搜索log4j.xml型材。如果不存在。我们将继续寻找log4j.properties文件,仅仅要找到当中一个就会载入该配置文件内容。


2.手动载入

假设将log4j.properties(或log4j.xml)放到其他文件夹下,比方下图中的位置,应用程序就不能自己主动载入log4j的配置文件了,由于应用程序找不到该配置文件,你须要手动载入。

须要在应用程序启动的代码中增加例如以下的代码:

//载入config目录下的log4j.properties
			String log4jPath=System.getProperty("user.dir")+"/config/log4j.properties";
			PropertyConfigurator.configure(log4jPath);

二.Spring中数据源配置文件位置

1.普通情况

比較常见的Spring载入数据源配置文件的方式例如以下:

<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:dataSource.properties</value>
			</list>
		</property>
	</bean>

这样的方式是将dataSource.properties文件放在src的根文件夹下的。

2.其他位置

如今假设将dataSource.properties文件放在src同级的config的文件夹下,上面的配置方式就不行了,正确的配置方式例如以下:

<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>file:config/dataSource.properties</value>
			</list>
		</property>
	</bean>

交流探讨到我的新浪微博:http://weibo.com/tianrui1990

版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Seata 是阿里巴巴开的一款分布式事务解决方案,它提供了高性能、易扩展、易集成的分布式事务解决方案,能够帮助我们解决分布式事务问题。 在 Spring Boot 和 Spring Cloud Alibaba 中集成 Seata 需要做以下几步操作: 1. 引入 Seata 的依赖 在 pom.xml 文件中引入 seata-all 的依赖: ```xml <dependency> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> <version>1.4.2</version> </dependency> ``` 2. 配置 Seata 的注册中心 在 application.properties 或 application.yml 文件配置 Seata 的注册中心地址: ```yaml seata: registry: type: nacos nacos: server-addr: localhost:8848 ``` 其中,type 表示注册中心的类型,这里设置为 nacos;nacos 表示 Nacos 注册中心的配置信息。 3. 配置 Seata 的事务组名称 在 application.properties 或 application.yml 文件配置 Seata 的事务组名称: ```yaml seata: tx-service-group: my_tx_group ``` 其中,tx-service-group 表示事务组名称,可以任意设置。 4. 配置 Seata 的数据代理 在 application.properties 或 application.yml 文件配置 Seata 的数据代理: ```yaml spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: 123456 seata: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: 123456 enable-auto-data-source-proxy: true ``` 其中,datasource 表示业务数据配置信息;seata.datasource 表示 Seata 数据配置信息;enable-auto-data-source-proxy 表示是否启用数据代理。 5. 配置 Seata 的代理数据 在 application.properties 或 application.yml 文件配置 Seata 的代理数据: ```yaml spring: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: 123456 seata: datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: 123456 enable-auto-data-source-proxy: true ``` 其中,type 表示数据的类型,这里使用的是阿里巴巴的 Druid 数据。 6. 配置 Seata 的 AT 模式 在 application.properties 或 application.yml 文件配置 Seata 的 AT 模式: ```yaml seata: service: vgroup-mapping: my_tx_group: default group-mapping: default: fescar-seata-example default-transaction-timeout: 300000 tx-service-group: my_tx_group mode: "AT" config: # AT 模式下的数据类型 client.db-type: "mysql" server: undo: log serialization: "json" log table: "undo_log" datasource: datasource: "seataDataSource" db-type: "mysql" ``` 其中,service.vgroup-mapping 表示事务组映射关系;service.group-mapping 表示事务组和注册中心的映射关系;default-transaction-timeout 表示默认的事务超时时间;tx-service-group 表示事务组名称;mode 表示 Seata 的模式,这里使用的是 AT 模式;config.client.db-type 表示 AT 模式下的数据类型;config.server.undo.log serialization 表示序列化方式;config.server.undo.log table 表示 undo log 表名;config.server.undo.datasource.datasource 表示 undo log 数据名称;config.server.undo.datasource.db-type 表示 undo log 数据类型。 7. 配置 Seata 的 TC 模式 在 application.properties 或 application.yml 文件配置 Seata 的 TC 模式: ```yaml seata: service: vgroup-mapping: my_tx_group: default group-mapping: default: fescar-seata-example default-transaction-timeout: 300000 tx-service-group: my_tx_group mode: "TC" config: server: port: 8091 max-commit-retry-timeout: 120000 max-rollback-retry-timeout: 120000 ``` 其中,server.port 表示 TC 模式下的端口号;config.server.max-commit-retry-timeout 表示最大提交重试时间;config.server.max-rollback-retry-timeout 表示最大回滚重试时间。 以上就是在 Spring Boot 和 Spring Cloud Alibaba 中集成 Seata 的详细配置步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值