简单实践 java spring boot 自动配置模拟

1.概要

1.1 需求,自己写一个redis-spring-boot-starter模拟自动配置

自动配置就是在引入*-starter坐标后,可以已经spring框架的规则实现一些Bean的自动注入,并设置一些参数的默认值,且也可以在引入的工程中修改这些配置的值。这里依据这个原理模拟一下。

1.2 要点

  • @Configuration
    @EnableConfigurationProperties(RedisProperties.class)
    public class RedisAutoConfigration {
        @Bean
        public Jedis jedis(RedisProperties edisProperties){
            return  new Jedis(edisProperties.getHost(),edisProperties.getPort());
  • @ConfigurationProperties
    public class RedisProperties {
  • <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
  • <artifactId>redis-spring-boot-autoconfigure</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  • <groupId>com.xjc.springcloundtest</groupId>
    <artifactId>redis-spring-boot-starter</artifactId>
  • Jedis jedis = context.getBean(Jedis.class);
    System.out.println(jedis);

1.3 关键词

  • @Configuration
  • @EnableConfigurationProperties(RedisProperties.class)
  • @Bean
  • @ConfigurationProperties
  • context.getBean(Jedis.class);
  • @SpringBootApplication
  • ConfigurableApplicationContext context =  SpringApplication.run(Main.class); 

2.代码

2.1 父工程

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.2</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.xjc.springcloundtest</groupId><artifactId>demo23</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><name>demo23</name><description>demo23</description><modules><module>redis-spring-boot-starter</module><module>redis-spring-boot-autoconfigure</module><module>untitled</module><module>untitled1</module></modules><properties><java.version>17</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
<!--		&lt;!&ndash; https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter &ndash;&gt;<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency>--></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2.2 启动工程  redis-spring-boot-starter 

2.2.1 工程文件

<?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"><modelVersion>4.0.0</modelVersion><parent><groupId>com.xjc.springcloundtest</groupId><artifactId>demo23</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>redis-spring-boot-starter</artifactId><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>com.xjc.springcloundtest</groupId><artifactId>redis-spring-boot-autoconfigure</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></project>

2.3 自动配置工程 redis-spring-boot-autoconfigure

2.3.1 工程文件

<?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"><modelVersion>4.0.0</modelVersion><parent><groupId>com.xjc.springcloundtest</groupId><artifactId>demo23</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>redis-spring-boot-autoconfigure</artifactId><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId></dependency></dependencies></project>

2.3.2 配置类

package com.xjc.springcloundtest;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
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.Configuration;
import redis.clients.jedis.Jedis;@Configuration
@EnableConfigurationProperties(RedisProperties.class)
public class RedisAutoConfigration {@Beanpublic Jedis jedis(RedisProperties edisProperties){return  new Jedis(edisProperties.getHost(),edisProperties.getPort());}
}

2.3.3 配置数据类

package com.xjc.springcloundtest;import org.springframework.boot.context.properties.ConfigurationProperties;@ConfigurationProperties
public class RedisProperties {public int getPort() {return port;}public void setPort(int port) {this.port = port;}public String getHost() {return host;}public void setHost(String host) {this.host = host;}private String host="localhost";private int port=6379;}

2.4  使用自定义自动配置工程进行测试

2.4.1 工程文件

<?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"><modelVersion>4.0.0</modelVersion><parent><groupId>com.xjc.springcloundtest</groupId><artifactId>demo23</artifactId><version>0.0.1-SNAPSHOT</version></parent><artifactId>untitled</artifactId><properties><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.xjc.springcloundtest</groupId><artifactId>redis-spring-boot-starter</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></project>

2.4.2 主函数

package com.xjc.springcloundtest;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import redis.clients.jedis.Jedis;@SpringBootApplication
public class Main {public static void main(String[] args) {ConfigurableApplicationContext context =  SpringApplication.run(Main.class);System.out.println("Hello world!");Jedis jedis = context.getBean(Jedis.class);System.out.println(jedis);}
}

2.4.3 测试结果

C:\Users\ThinkPad\.jdks\openjdk-21.0.2\bin\java.exe -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=61994:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.2.2\spring-boot-starter-web-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.2.2\spring-boot-starter-json-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.15.3\jackson-databind-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.15.3\jackson-annotations-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.15.3\jackson-core-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.15.3\jackson-datatype-jdk8-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.15.3\jackson-datatype-jsr310-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.15.3\jackson-module-parameter-names-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.2.2\spring-boot-starter-tomcat-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.18\tomcat-embed-core-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.18\tomcat-embed-el-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.18\tomcat-embed-websocket-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-web\6.1.3\spring-web-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-beans\6.1.3\spring-beans-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-observation\1.12.2\micrometer-observation-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-commons\1.12.2\micrometer-commons-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-webmvc\6.1.3\spring-webmvc-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-aop\6.1.3\spring-aop-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-context\6.1.3\spring-context-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-expression\6.1.3\spring-expression-6.1.3.jar;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-starter\target\classes;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-autoconfigure\target\classes;C:\Users\ThinkPad\.m2\repository\redis\clients\jedis\5.0.2\jedis-5.0.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\commons\commons-pool2\2.12.0\commons-pool2-2.12.0.jar;C:\Users\ThinkPad\.m2\repository\org\json\json\20231013\json-20231013.jar;C:\Users\ThinkPad\.m2\repository\com\google\code\gson\gson\2.10.1\gson-2.10.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter\3.2.2\spring-boot-starter-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot\3.2.2\spring-boot-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.2.2\spring-boot-autoconfigure-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.2.2\spring-boot-starter-logging-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-classic\1.4.14\logback-classic-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-core\1.4.14\logback-core-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.21.1\log4j-to-slf4j-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-api\2.21.1\log4j-api-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\jul-to-slf4j\2.0.11\jul-to-slf4j-2.0.11.jar;C:\Users\ThinkPad\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-core\6.1.3\spring-core-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-jcl\6.1.3\spring-jcl-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\yaml\snakeyaml\2.2\snakeyaml-2.2.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\slf4j-api\2.0.11\slf4j-api-2.0.11.jar com.xjc.springcloundtest.Main.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::                (v3.2.2)2024-02-02T16:04:44.406+08:00  INFO 22288 --- [           main] com.xjc.springcloundtest.Main            : Starting Main using Java 21.0.2 with PID 22288 (C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes started by ThinkPad in C:\Users\ThinkPad\IdeaProjects\demo23)
2024-02-02T16:04:44.410+08:00  INFO 22288 --- [           main] com.xjc.springcloundtest.Main            : No active profile set, falling back to 1 default profile: "default"
2024-02-02T16:04:45.388+08:00  INFO 22288 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-02-02T16:04:45.400+08:00  INFO 22288 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-02-02T16:04:45.400+08:00  INFO 22288 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.18]
2024-02-02T16:04:45.452+08:00  INFO 22288 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-02-02T16:04:45.453+08:00  INFO 22288 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 978 ms
2024-02-02T16:04:45.963+08:00  INFO 22288 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2024-02-02T16:04:45.970+08:00  INFO 22288 --- [           main] com.xjc.springcloundtest.Main            : Started Main in 2.054 seconds (process running for 2.705)
Hello world!
Jedis{Connection{DefaultJedisSocketFactory{localhost:6379}}}

3 补充实验

3.1 概要

实验条件加载的效果,给对象加一个软件,如果用户已经创建了这个对象,就不再创建了。

3.2 代码 

3.2 添加条件 

3.2.1 配置文件变更 @ConditionalOnMissingBean(name = "jedis")

@Configuration
@EnableConfigurationProperties(RedisProperties.class)
public class RedisAutoConfigration {@Bean@ConditionalOnMissingBean(name = "jedis")public Jedis jedis(RedisProperties edisProperties){System.out.println("自动配置Jedis");return  new Jedis(edisProperties.getHost(),edisProperties.getPort());}
}

3.2.1 测试函数变更 添加Jedis 对象的Bean

@SpringBootApplication
public class Main {public static void main(String[] args) {ConfigurableApplicationContext context =  SpringApplication.run(Main.class);System.out.println("Hello world!");//Jedis jedis = context.getBean(Jedis.class);Object o = context.getBean("jedis");System.out.println(o);}@Beanpublic Jedis jedis2(){return  new Jedis("localhost",6379);}
}

3.3 测试结果

C:\Users\ThinkPad\.jdks\openjdk-21.0.2\bin\java.exe -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=63505:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.2.2\spring-boot-starter-web-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.2.2\spring-boot-starter-json-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.15.3\jackson-databind-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.15.3\jackson-annotations-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.15.3\jackson-core-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.15.3\jackson-datatype-jdk8-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.15.3\jackson-datatype-jsr310-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.15.3\jackson-module-parameter-names-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.2.2\spring-boot-starter-tomcat-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.18\tomcat-embed-core-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.18\tomcat-embed-el-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.18\tomcat-embed-websocket-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-web\6.1.3\spring-web-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-beans\6.1.3\spring-beans-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-observation\1.12.2\micrometer-observation-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-commons\1.12.2\micrometer-commons-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-webmvc\6.1.3\spring-webmvc-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-aop\6.1.3\spring-aop-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-context\6.1.3\spring-context-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-expression\6.1.3\spring-expression-6.1.3.jar;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-starter\target\classes;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-autoconfigure\target\classes;C:\Users\ThinkPad\.m2\repository\redis\clients\jedis\5.0.2\jedis-5.0.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\commons\commons-pool2\2.12.0\commons-pool2-2.12.0.jar;C:\Users\ThinkPad\.m2\repository\org\json\json\20231013\json-20231013.jar;C:\Users\ThinkPad\.m2\repository\com\google\code\gson\gson\2.10.1\gson-2.10.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter\3.2.2\spring-boot-starter-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot\3.2.2\spring-boot-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.2.2\spring-boot-autoconfigure-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.2.2\spring-boot-starter-logging-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-classic\1.4.14\logback-classic-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-core\1.4.14\logback-core-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.21.1\log4j-to-slf4j-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-api\2.21.1\log4j-api-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\jul-to-slf4j\2.0.11\jul-to-slf4j-2.0.11.jar;C:\Users\ThinkPad\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-core\6.1.3\spring-core-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-jcl\6.1.3\spring-jcl-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\yaml\snakeyaml\2.2\snakeyaml-2.2.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\slf4j-api\2.0.11\slf4j-api-2.0.11.jar com.xjc.springcloundtest.Main.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::                (v3.2.2)2024-02-02T16:59:08.925+08:00  INFO 42840 --- [           main] com.xjc.springcloundtest.Main            : Starting Main using Java 21.0.2 with PID 42840 (C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes started by ThinkPad in C:\Users\ThinkPad\IdeaProjects\demo23)
2024-02-02T16:59:08.929+08:00  INFO 42840 --- [           main] com.xjc.springcloundtest.Main            : No active profile set, falling back to 1 default profile: "default"
2024-02-02T16:59:09.780+08:00  INFO 42840 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-02-02T16:59:09.790+08:00  INFO 42840 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-02-02T16:59:09.790+08:00  INFO 42840 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.18]
2024-02-02T16:59:09.833+08:00  INFO 42840 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-02-02T16:59:09.834+08:00  INFO 42840 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 843 ms
自动配置Jedis
2024-02-02T16:59:10.281+08:00  INFO 42840 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2024-02-02T16:59:10.287+08:00  INFO 42840 --- [           main] com.xjc.springcloundtest.Main            : Started Main in 1.831 seconds (process running for 2.547)
Hello world!
Jedis{Connection{DefaultJedisSocketFactory{localhost:6379}}}Process finished with exit code 130

3.4 让两处的名称相同

3.4.1 代码

//自动配置处 
@Bean@ConditionalOnMissingBean(name = "jedis")public Jedis jedis(RedisProperties edisProperties){System.out.println("自动配置Jedis");return  new Jedis(edisProperties.getHost(),edisProperties.getPort());}
//主动配置出
@Beanpublic Jedis jedis(){return  new Jedis("localhost",6379);}

3.4.2 测结果 还没有到加载bena的时候就报错了

C:\Users\ThinkPad\.jdks\openjdk-21.0.2\bin\java.exe -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=65274:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.2.2\spring-boot-starter-web-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.2.2\spring-boot-starter-json-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.15.3\jackson-databind-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.15.3\jackson-annotations-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.15.3\jackson-core-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.15.3\jackson-datatype-jdk8-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.15.3\jackson-datatype-jsr310-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.15.3\jackson-module-parameter-names-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.2.2\spring-boot-starter-tomcat-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.18\tomcat-embed-core-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.18\tomcat-embed-el-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.18\tomcat-embed-websocket-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-web\6.1.3\spring-web-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-beans\6.1.3\spring-beans-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-observation\1.12.2\micrometer-observation-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-commons\1.12.2\micrometer-commons-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-webmvc\6.1.3\spring-webmvc-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-aop\6.1.3\spring-aop-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-context\6.1.3\spring-context-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-expression\6.1.3\spring-expression-6.1.3.jar;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-starter\target\classes;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-autoconfigure\target\classes;C:\Users\ThinkPad\.m2\repository\redis\clients\jedis\5.0.2\jedis-5.0.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\commons\commons-pool2\2.12.0\commons-pool2-2.12.0.jar;C:\Users\ThinkPad\.m2\repository\org\json\json\20231013\json-20231013.jar;C:\Users\ThinkPad\.m2\repository\com\google\code\gson\gson\2.10.1\gson-2.10.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter\3.2.2\spring-boot-starter-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot\3.2.2\spring-boot-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.2.2\spring-boot-autoconfigure-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.2.2\spring-boot-starter-logging-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-classic\1.4.14\logback-classic-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-core\1.4.14\logback-core-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.21.1\log4j-to-slf4j-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-api\2.21.1\log4j-api-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\jul-to-slf4j\2.0.11\jul-to-slf4j-2.0.11.jar;C:\Users\ThinkPad\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-core\6.1.3\spring-core-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-jcl\6.1.3\spring-jcl-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\yaml\snakeyaml\2.2\snakeyaml-2.2.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\slf4j-api\2.0.11\slf4j-api-2.0.11.jar com.xjc.springcloundtest.Main.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::                (v3.2.2)2024-02-02T18:39:34.394+08:00  INFO 42764 --- [           main] com.xjc.springcloundtest.Main            : Starting Main using Java 21.0.2 with PID 42764 (C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes started by ThinkPad in C:\Users\ThinkPad\IdeaProjects\demo23)
2024-02-02T18:39:34.396+08:00  INFO 42764 --- [           main] com.xjc.springcloundtest.Main            : No active profile set, falling back to 1 default profile: "default"
2024-02-02T18:39:34.729+08:00  WARN 42764 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'jedis' defined in com.xjc.springcloundtest.Main: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=main; factoryMethodName=jedis; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in com.xjc.springcloundtest.Main] for bean 'jedis' since there is already [Root bean: class [null]; scope=; abstract=false; lazyInit=null; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=redisAutoConfigration; factoryMethodName=jedis; initMethodNames=null; destroyMethodNames=[(inferred)]; defined in class path resource [com/xjc/springcloundtest/RedisAutoConfigration.class]] bound.
2024-02-02T18:39:34.735+08:00  INFO 42764 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-02-02T18:39:34.754+08:00 ERROR 42764 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : ***************************
APPLICATION FAILED TO START
***************************Description:The bean 'jedis', defined in com.xjc.springcloundtest.Main, could not be registered. A bean with that name has already been defined in class path resource [com/xjc/springcloundtest/RedisAutoConfigration.class] and overriding is disabled.Action:Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=trueProcess finished with exit code 1

3.4.3 添加配置

spring:main:allow-bean-definition-overriding: true
C:\Users\ThinkPad\.jdks\openjdk-21.0.2\bin\java.exe -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=65297:D:\Program Files\JetBrains\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-web\3.2.2\spring-boot-starter-web-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-json\3.2.2\spring-boot-starter-json-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.15.3\jackson-databind-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.15.3\jackson-annotations-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.15.3\jackson-core-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.15.3\jackson-datatype-jdk8-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.15.3\jackson-datatype-jsr310-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.15.3\jackson-module-parameter-names-2.15.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\3.2.2\spring-boot-starter-tomcat-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\10.1.18\tomcat-embed-core-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\10.1.18\tomcat-embed-el-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\10.1.18\tomcat-embed-websocket-10.1.18.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-web\6.1.3\spring-web-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-beans\6.1.3\spring-beans-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-observation\1.12.2\micrometer-observation-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\io\micrometer\micrometer-commons\1.12.2\micrometer-commons-1.12.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-webmvc\6.1.3\spring-webmvc-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-aop\6.1.3\spring-aop-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-context\6.1.3\spring-context-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-expression\6.1.3\spring-expression-6.1.3.jar;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-starter\target\classes;C:\Users\ThinkPad\IdeaProjects\demo23\redis-spring-boot-autoconfigure\target\classes;C:\Users\ThinkPad\.m2\repository\redis\clients\jedis\5.0.2\jedis-5.0.2.jar;C:\Users\ThinkPad\.m2\repository\org\apache\commons\commons-pool2\2.12.0\commons-pool2-2.12.0.jar;C:\Users\ThinkPad\.m2\repository\org\json\json\20231013\json-20231013.jar;C:\Users\ThinkPad\.m2\repository\com\google\code\gson\gson\2.10.1\gson-2.10.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter\3.2.2\spring-boot-starter-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot\3.2.2\spring-boot-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\3.2.2\spring-boot-autoconfigure-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\boot\spring-boot-starter-logging\3.2.2\spring-boot-starter-logging-3.2.2.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-classic\1.4.14\logback-classic-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\ch\qos\logback\logback-core\1.4.14\logback-core-1.4.14.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.21.1\log4j-to-slf4j-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\apache\logging\log4j\log4j-api\2.21.1\log4j-api-2.21.1.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\jul-to-slf4j\2.0.11\jul-to-slf4j-2.0.11.jar;C:\Users\ThinkPad\.m2\repository\jakarta\annotation\jakarta.annotation-api\2.1.1\jakarta.annotation-api-2.1.1.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-core\6.1.3\spring-core-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\springframework\spring-jcl\6.1.3\spring-jcl-6.1.3.jar;C:\Users\ThinkPad\.m2\repository\org\yaml\snakeyaml\2.2\snakeyaml-2.2.jar;C:\Users\ThinkPad\.m2\repository\org\slf4j\slf4j-api\2.0.11\slf4j-api-2.0.11.jar com.xjc.springcloundtest.Main.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::                (v3.2.2)2024-02-02T18:41:04.833+08:00  INFO 40908 --- [           main] com.xjc.springcloundtest.Main            : Starting Main using Java 21.0.2 with PID 40908 (C:\Users\ThinkPad\IdeaProjects\demo23\untitled\target\classes started by ThinkPad in C:\Users\ThinkPad\IdeaProjects\demo23)
2024-02-02T18:41:04.835+08:00  INFO 40908 --- [           main] com.xjc.springcloundtest.Main            : No active profile set, falling back to 1 default profile: "default"
2024-02-02T18:41:05.636+08:00  INFO 40908 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2024-02-02T18:41:05.648+08:00  INFO 40908 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2024-02-02T18:41:05.648+08:00  INFO 40908 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.18]
2024-02-02T18:41:05.696+08:00  INFO 40908 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2024-02-02T18:41:05.696+08:00  INFO 40908 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 805 ms
2024-02-02T18:41:06.119+08:00  INFO 40908 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port 8080 (http) with context path ''
2024-02-02T18:41:06.124+08:00  INFO 40908 --- [           main] com.xjc.springcloundtest.Main            : Started Main in 1.856 seconds (process running for 2.624)
Hello world!
Jedis{Connection{DefaultJedisSocketFactory{localhost:6379}}}

这时候才达到对比的效果

@Bean@ConditionalOnMissingBean(name = "jedis")public Jedis jedis(RedisProperties edisProperties){System.out.println("自动配置Jedis");return  new Jedis(edisProperties.getHost(),edisProperties.getPort());}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/448932.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

FANUC机器人示教器的菜单变成了图标,如何改成列表的形式?

FANUC机器人示教器的菜单变成了图标&#xff0c;如何改成列表的形式&#xff1f; 如下图所示&#xff0c;开机后按下MENU菜单键时&#xff0c;发现原来的列表形式变成了菜单图标的形式&#xff0c;同时在按F1-F5键时&#xff0c;提示&#xff1a;HMI模式-键不可用&#xff0c; …

企业申请sectigo ip https证书

Sectigo&#xff08;原名Comodo&#xff0c;在整合https证书业务后改名为Sectigo&#xff09;是一家知名的数字证书提供商&#xff0c;拥有多种类型的数字证书&#xff0c;例如单域名https证书、多域名https证书、通配符https证书、IP https证书和代码签名证书等满足各类用户的…

使用VScode编译betaflight固件--基于ubuntu平台

使用VScode编译betaflight固件--基于ubuntu平台 1、使用git克隆betaflight的开源代码2、配置编译环境3、使用VScode编译代码 window平台的见上一篇文章 使用VScode编译betaflight固件–基于windows平台 本文主要介绍在linux系统 ubuntu平台下使用VScode编译betaflight固件的方法…

某宝 bx-pp参数 反编译wasm还原算法

声明: 本文章中所有内容仅供学习交流&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff0c;若有侵权&#xff0c;请联系我立即删除&#xff01; 前言: 听说最近某宝水果滑块出了一个bx-pp参数 是wasm加密,抱着好奇的心态打开的网…

TCP 连接掉线自动重连

文章目录 TCP 连接掉线自动重连定义使用连接效果 TCP 接收数据时防止掉线。TCP 连接掉线自动重连。多线程环境下TCP掉线自动重连。 欢迎讨论更好的方法&#xff01; TCP 连接掉线自动重连 定义 定义一个类&#xff0c;以编写TCP连接函数Connect()&#xff0c;并且&#xff1a…

MySQL原理(五)事务

一、介绍&#xff1a; 1、介绍&#xff1a; 在计算机术语中&#xff0c;事务(Transaction)是访问并可能更新数据库中各种数据项的一个程序执行单元(unit)。事务是恢复和并发控制的基本单位。 2、事务的4大特性 原子性、一致性、隔离性、持久性。这四个属性通常称为ACID特性…

比瓴科技入围软件供应链安全赛道!为关键信息基础设施安全建设注入新动力

1月20日&#xff0c;中关村华安关键信息基础设施安全保护联盟会员大会暨关键信息基础设施安全保护论坛在北京成功举办&#xff0c;比瓴科技作为会员单位受邀出席。 本次论坛发布了《关键信息基础设施安全保护支撑能力白皮书&#xff08;2023&#xff09;》&#xff0c;比瓴科技…

Jmeter直连mysql数据库教程

mysql数据库能够通过Navicat等远程连接工具连接 下载驱动并加入jmeter 1.mysql驱动下载地址&#xff1a;MySQL :: Download MySQL Connector/J (Archived Versions) 找到对应的驱动下载&#xff1a;如下图&#xff1a; 把驱动jar包加入jmeter 配置jmeter连接mysql数据库…

区间时间检索

前端 <el-col :md"6" v-if"advanced"><el-form-item :label"$t(inRecord.column.createTime)"><el-date-pickerstyle"width: 100%;"v-model"daterangeCreateTime"value-format"yyyy-MM-dd"type&qu…

【sentinel流量卫兵搭建与微服务整合】

sentinel流量卫兵搭建与微服务整合 搭建sentinel dashboard控制台微服务整合 搭建sentinel dashboard控制台 1、下载 官网链接 由于官网github网络原因&#xff0c;导致长时间下载失败。 网盘链接 网盘提取码&#xff1a;dwgj 2、运行 将下载jar包放在任意非中文、不包含特殊…

Java数组的遍历

目录 数组的遍历使用for循环遍历数组使用for-each循环遍历数组使用while循环和迭代器遍历数组使用Java 8的流API遍历数组 数组遍历的应用求数组中的最大值查询数组中指定位置的元素将查指定元素对应的索引的功能提取为方法添加数组元素删除数组元素 数组的遍历 Java数组的遍历…

【Kafka专栏】windows搭建Kafka环境 详细教程(01)

文章目录 01 引言1.1 官网地址1.2 概述简介1.3 kafka与zookeeper 02 部署zookeeper2.1 下载组件包2.2 解压压缩包&#xff08;1&#xff09;解压到任意路径&#xff08;2&#xff09;解压后的目录创建数据目录data 2.3 修改zoo配置2.4 设置系统变量2.5 启动zookeepe服务&#x…