short-url-spring-boot-starter
This commit is contained in:
parent
93aeb8266a
commit
e906c5de43
7
pom.xml
7
pom.xml
|
@ -4,6 +4,12 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<version>2.7.1</version>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<groupId>cn.zzzykj</groupId>
|
<groupId>cn.zzzykj</groupId>
|
||||||
<artifactId>zy-short-url</artifactId>
|
<artifactId>zy-short-url</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
@ -12,6 +18,7 @@
|
||||||
<module>zy-shorturl-core</module>
|
<module>zy-shorturl-core</module>
|
||||||
<module>zy-shorturl-spring-boot-starter</module>
|
<module>zy-shorturl-spring-boot-starter</module>
|
||||||
<module>zy-shorturl-store</module>
|
<module>zy-shorturl-store</module>
|
||||||
|
<module>zu-shorturl-web</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
48
zu-shorturl-web/pom.xml
Normal file
48
zu-shorturl-web/pom.xml
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>zy-short-url</artifactId>
|
||||||
|
<groupId>cn.zzzykj</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>zu-shorturl-web</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- zy-shorturl -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.zzzykj</groupId>
|
||||||
|
<artifactId>zy-short-url-spring-boot-starter</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringBoot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,18 @@
|
||||||
|
package cn.shorturl.web;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZhuoQinghui
|
||||||
|
* @version 1.0.0
|
||||||
|
* Create By 2022/7/31 16:15
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package cn.shorturl.web.controller;
|
||||||
|
|
||||||
|
import cn.shorturl.core.ShortUrlConfig;
|
||||||
|
import cn.shorturl.store.ShortUrlStore;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZhuoQinghui
|
||||||
|
* @version 1.0.0
|
||||||
|
* Create By 2022/7/31 16:41
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/su")
|
||||||
|
public class ShortUrlController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ShortUrlConfig shortUrlConfig;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ShortUrlStore store;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
log.info("shortUrlConfig: {}", shortUrlConfig);
|
||||||
|
log.info("store: {}", store);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/gen")
|
||||||
|
public String gen() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
zu-shorturl-web/src/main/resources/application.yml
Normal file
7
zu-shorturl-web/src/main/resources/application.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
server:
|
||||||
|
port: 8090
|
||||||
|
|
||||||
|
shorturl:
|
||||||
|
store:
|
||||||
|
retryMax: 6
|
||||||
|
store-type: redis
|
|
@ -17,4 +17,32 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- spring-boot -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- zy-shorturl-store -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.zzzykj</groupId>
|
||||||
|
<artifactId>zy-shorturl-store</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- lombok -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,50 @@
|
||||||
|
package cn.shorturl.boot.starter;
|
||||||
|
|
||||||
|
import cn.shorturl.core.ShortUrlConfig;
|
||||||
|
import cn.shorturl.core.ShortUrlUtil;
|
||||||
|
import cn.shorturl.store.ShortUrlStore;
|
||||||
|
import cn.shorturl.store.store.RedisShortUrlStore;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ZhuoQinghui
|
||||||
|
* @version 1.0.0
|
||||||
|
* Create By 2022/7/31 16:25
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public class ShortUrlAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(ShortUrlConfig.class)
|
||||||
|
@ConfigurationProperties(prefix = "shorturl.store")
|
||||||
|
public ShortUrlConfig shortUrlConfig() {
|
||||||
|
return new ShortUrlConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(ShortUrlConfig.class)
|
||||||
|
public ShortUrlUtil shortUrlUtil(ShortUrlConfig config) {
|
||||||
|
return new ShortUrlUtil(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(ShortUrlStore.class)
|
||||||
|
@ConditionalOnProperty(prefix = "shorturl.store", name = "store-type", havingValue = "redis")
|
||||||
|
public ShortUrlStore redisShortUrlStore() {
|
||||||
|
log.info("use short-url store: {}", RedisShortUrlStore.class.getName());
|
||||||
|
return new RedisShortUrlStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
cn.shorturl.boot.starter.ShortUrlAutoConfiguration
|
|
@ -23,20 +23,6 @@
|
||||||
<artifactId>zy-short-url-core</artifactId>
|
<artifactId>zy-short-url-core</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
|
||||||
<version>2.7.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
|
|
||||||
<version>2.7.2</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,22 +0,0 @@
|
||||||
package cn.shorturl.store.config;
|
|
||||||
|
|
||||||
import cn.shorturl.core.ShortUrlConfig;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
@EnableConfigurationProperties
|
|
||||||
@ComponentScan(basePackages = "cn.shorturl.store")
|
|
||||||
public class BeanRegister {
|
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "shorturl.store")
|
|
||||||
public ShortUrlConfig shortUrlConfig(ShortUrlConfig shortUrlConfig) {
|
|
||||||
return shortUrlConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -3,21 +3,12 @@ package cn.shorturl.store.store;
|
||||||
import cn.shorturl.core.ShortUrl;
|
import cn.shorturl.core.ShortUrl;
|
||||||
import cn.shorturl.core.ShortUrlConfig;
|
import cn.shorturl.core.ShortUrlConfig;
|
||||||
import cn.shorturl.store.ShortUrlStore;
|
import cn.shorturl.store.ShortUrlStore;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Lenovo
|
* @author Lenovo
|
||||||
*/
|
*/
|
||||||
@ConditionalOnProperty(prefix = "shorturl.store", name = "storeType", havingValue = "redis")
|
|
||||||
public class RedisShortUrlStore implements ShortUrlStore {
|
public class RedisShortUrlStore implements ShortUrlStore {
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
System.out.println("RedisShortUrlStore init");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShortUrl add(ShortUrl shortUrl) {
|
public ShortUrl add(ShortUrl shortUrl) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user