Skip to content

Commit b2fb06f

Browse files
committed
add leaf properties
1 parent 7aa33db commit b2fb06f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

springboot-starter-leaf/src/main/java/com/codingapi/springboot/leaf/AutoConfiguration.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
package com.codingapi.springboot.leaf;
22

3+
import com.codingapi.springboot.leaf.properties.LeafProperties;
34
import com.sankuai.inf.leaf.IDGen;
45
import com.sankuai.inf.leaf.segment.SegmentIDGenImpl;
56
import com.sankuai.inf.leaf.segment.dao.IDAllocDao;
67
import com.sankuai.inf.leaf.segment.dao.impl.IDAllocDaoImpl;
7-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
8+
import org.springframework.boot.context.properties.ConfigurationProperties;
89
import org.springframework.context.annotation.Bean;
910
import org.springframework.context.annotation.Configuration;
1011

1112
@Configuration
1213
public class AutoConfiguration {
1314

1415
@Bean
15-
@ConditionalOnMissingBean
16-
public IDAllocDao allocDao(){
17-
return new IDAllocDaoImpl("jdbc:h2:mem:leaf;DB_CLOSE_DELAY=-1");
16+
@ConfigurationProperties(prefix = "codingapi.leaf")
17+
public LeafProperties leafProperties(){
18+
return new LeafProperties();
19+
}
20+
21+
@Bean
22+
public IDAllocDao allocDao(LeafProperties leafProperties){
23+
return new IDAllocDaoImpl(leafProperties.getJdbcUrl());
1824
}
1925

2026

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.codingapi.springboot.leaf.properties;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Setter
7+
@Getter
8+
public class LeafProperties {
9+
10+
private String jdbcUrl = "jdbc:h2:mem:leaf;DB_CLOSE_DELAY=-1";
11+
12+
}

0 commit comments

Comments
 (0)