edit
This commit is contained in:
parent
9538d87257
commit
387299c43b
@ -1,16 +0,0 @@
|
||||
package com.ybw.spi.jdk.demo.service;
|
||||
|
||||
|
||||
/**
|
||||
* Demo service. Implements should be use SPI.
|
||||
*
|
||||
* @author ybw
|
||||
* @version V1.0
|
||||
* @className DemoService
|
||||
* @date 2022/6/29
|
||||
**/
|
||||
public interface DemoService {
|
||||
|
||||
String sayHello();
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.ybw.spi.jdk.demo.service.impl;
|
||||
|
||||
import com.ybw.spi.jdk.demo.service.DemoService;
|
||||
|
||||
/**
|
||||
* Implement for DemoService
|
||||
*
|
||||
* @author ybw
|
||||
* @version V1.0
|
||||
* @className DemoOneServiceImpl
|
||||
* @date 2022/6/29
|
||||
**/
|
||||
public class DemoOneServiceImpl implements DemoService {
|
||||
|
||||
@Override
|
||||
public String sayHello() {
|
||||
return "hello world one";
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.ybw.spi.jdk.demo.service.impl;
|
||||
|
||||
import com.ybw.spi.jdk.demo.service.DemoService;
|
||||
|
||||
/**
|
||||
* Implement for DemoService
|
||||
*
|
||||
* @author ybw
|
||||
* @version V1.0
|
||||
* @className DemoOneServiceImpl
|
||||
* @date 2022/6/29
|
||||
**/
|
||||
public class DemoTwoServiceImpl implements DemoService {
|
||||
|
||||
@Override
|
||||
public String sayHello() {
|
||||
return "hello world two";
|
||||
}
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
com.ybw.spi.jdk.demo.service.impl.DemoOneServiceImpl
|
||||
com.ybw.spi.jdk.demo.service.impl.DemoTwoServiceImpl
|
@ -1,63 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径 -->
|
||||
<!-- <property name="LOG_HOME" value="d:" /> -->
|
||||
|
||||
<!-- ch.qos.logback.core.ConsoleAppender 控制台输出 -->
|
||||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- error日志输出 -->
|
||||
<appender name="ErrorFile"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${LOG_HOME:-c:/}logs/error/error.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${LOG_HOME:-c:/}logs/error/error-%d{yyyy-MM-dd}.%i.log
|
||||
</FileNamePattern>
|
||||
<MaxHistory>3600</MaxHistory>
|
||||
<TimeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<MaxFileSize>100MB</MaxFileSize>
|
||||
</TimeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</layout>
|
||||
<filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印错误日志 -->
|
||||
<level>ERROR</level>
|
||||
<onMatch>ACCEPT</onMatch>
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<!-- 所有日志输出 -->
|
||||
<appender name="AllFile"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<File>${LOG_HOME:-c:/}logs/all/all.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${LOG_HOME:-c:/}logs/all/all-%d{yyyy-MM-dd}.%i.log
|
||||
</FileNamePattern>
|
||||
<MaxHistory>3600</MaxHistory>
|
||||
<TimeBasedFileNamingAndTriggeringPolicy
|
||||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<MaxFileSize>100MB</MaxFileSize>
|
||||
</TimeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="stdout" />
|
||||
<appender-ref ref="ErrorFile" />
|
||||
<appender-ref ref="AllFile" />
|
||||
</root>
|
||||
</configuration>
|
@ -1,35 +0,0 @@
|
||||
package com.ybw.spi.jdk.demo.app;
|
||||
|
||||
import com.ybw.spi.jdk.demo.service.DemoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* 加载使用
|
||||
*
|
||||
* @author ybw
|
||||
* @version V1.0
|
||||
* @className SpiTest
|
||||
* @date 2022/6/29
|
||||
**/
|
||||
@Slf4j
|
||||
public class SpiTest {
|
||||
|
||||
/**
|
||||
* @methodName: spiTest
|
||||
* @return: void
|
||||
* @author: ybw
|
||||
* @date: 2022/6/29
|
||||
**/
|
||||
@Test
|
||||
public void spiTest() {
|
||||
ServiceLoader<DemoService> demoServices = ServiceLoader.load(DemoService.class);
|
||||
demoServices.forEach(demoService -> {
|
||||
log.info(demoService.getClass().getName());
|
||||
log.info("ClassLoader:{}",demoService.getClass().getClassLoader());
|
||||
log.info(demoService.sayHello());
|
||||
});
|
||||
}
|
||||
}
|
@ -3,16 +3,16 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.ybw</groupId>
|
||||
<artifactId>spi-jdk-demo</artifactId>
|
||||
<artifactId>spring-demo-starter</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>spi-jdk-demo</name>
|
||||
<description>SPI全称,Service Provider Interface,服务提供者接口</description>
|
||||
<name>spring-demo-starter</name>
|
||||
<description>自定义starter</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-boot.version>2.6.6</spring-boot.version>
|
||||
<spring-boot.version>2.4.1</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -60,9 +60,9 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<version>2.4.1</version>
|
||||
<configuration>
|
||||
<mainClass>com.ybw.spi.jdk.demo.SpiJdkDemoApplication</mainClass>
|
||||
<mainClass>com.ybw.spring.demo.starter.SpringDemoStarterApplication</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
@ -0,0 +1,13 @@
|
||||
package com.ybw.spring.demo.starter;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringDemoStarterApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringDemoStarterApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
# 应用名称
|
||||
spring.application.name=spring-demo-starter
|
||||
# 应用服务 WEB 访问端口
|
||||
server.port=8080
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.ybw.spring.demo.starter;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringDemoStarterApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user