Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions microsphere-spring-cloud-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@

<dependencies>

<!-- Microsphere Dependencies -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-webmvc</artifactId>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-webflux</artifactId>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-actuator</artifactId>
<optional>true</optional>
</dependency>

<!-- Spring Boot Dependencies -->
Expand Down Expand Up @@ -109,28 +121,9 @@
<optional>true</optional>
</dependency>

<!-- Microsphere Dependencies -->
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-core</artifactId>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-boot-actuator</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-webmvc</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-spring-webflux</artifactId>
<optional>true</optional>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>

<!-- Testing -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@

import io.microsphere.spring.cloud.commons.constants.CommonsPropertyConstants;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
import org.springframework.cloud.client.actuator.FeaturesEndpoint;
import org.springframework.cloud.client.actuator.HasFeatures;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static io.microsphere.spring.cloud.commons.constants.CommonsPropertyConstants.FEATURES_ENABLED_PROPERTY_NAME;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@

import io.microsphere.annotation.ConfigurationProperty;
import io.microsphere.spring.cloud.client.discovery.UnionDiscoveryClient;
import io.microsphere.spring.cloud.client.discovery.condition.ConditionalOnBlockingDiscoveryAvailable;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static io.microsphere.annotation.ConfigurationProperty.APPLICATION_SOURCE;
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.DISCOVERY_CLIENT_CLASS_NAME;
import static io.microsphere.spring.cloud.commons.constants.CommonsPropertyConstants.MICROSPHERE_SPRING_CLOUD_PROPERTY_NAME_PREFIX;

/**
Expand All @@ -42,11 +39,7 @@
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = {
DISCOVERY_CLIENT_CLASS_NAME
})
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
@ConditionalOnBlockingDiscoveryAvailable
@AutoConfigureBefore(name = {
COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
package io.microsphere.spring.cloud.client.discovery.autoconfigure;

import io.microsphere.spring.cloud.client.discovery.ReactiveDiscoveryClientAdapter;
import io.microsphere.spring.cloud.client.discovery.condition.ConditionalOnReactiveDiscoveryAvailable;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.DISCOVERY_CLIENT_CLASS_NAME;
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.REACTIVE_COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.REACTIVE_COMPOSITE_DISCOVERY_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.SIMPLE_REACTIVE_DISCOVERY_CLIENT_AUTO_CONFIGURATION_CLASS_NAME;
Expand All @@ -43,11 +40,7 @@
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = {
DISCOVERY_CLIENT_CLASS_NAME
})
@ConditionalOnDiscoveryEnabled
@ConditionalOnReactiveDiscoveryEnabled
@ConditionalOnReactiveDiscoveryAvailable
@AutoConfigureBefore(name = {
REACTIVE_COMMONS_CLIENT_AUTO_CONFIGURATION_CLASS_NAME
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.microsphere.spring.cloud.client.discovery.condition;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.DISCOVERY_CLIENT_CLASS_NAME;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* A condition that checks if Blocking Spring Cloud Discovery is available.
* <p>
* This annotation combines {@link ConditionalOnClass} (checking for the presence of {@code DiscoveryClient}),
* {@link ConditionalOnDiscoveryEnabled}, and {@link ConditionalOnBlockingDiscoveryEnabled} to ensure that
* the discovery client is both present in the classpath and enabled for blocking operations.
*
* <h3>Example Usage:</h3>
* <pre>{@code
* @Configuration
* @ConditionalOnDiscoveryAvailable
* public class DiscoveryClientConfiguration {
*
* @Bean
* public MyService myService(DiscoveryClient discoveryClient) {
* return new MyService(discoveryClient);
* }
* }
* }</pre>
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see ConditionalOnDiscoveryEnabled
* @see ConditionalOnBlockingDiscoveryEnabled
* @see ConditionalOnClass
* @since 1.0.0
*/
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Documented
@Inherited
@ConditionalOnClass(name = {
DISCOVERY_CLIENT_CLASS_NAME
})
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
public @interface ConditionalOnBlockingDiscoveryAvailable {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.microsphere.spring.cloud.client.discovery.condition;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled;
import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static io.microsphere.spring.cloud.client.discovery.constants.DiscoveryClientConstants.REACTIVE_DISCOVERY_CLIENT_CLASS_NAME;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* {@link ConditionalOnReactiveDiscoveryEnabled} and {@link ConditionalOnClass} for Reactive Discovery Client.
* <p>
* This annotation can be used to conditionally enable a bean or configuration only when:
* <ul>
* <li>The Spring Cloud Discovery is enabled ({@link ConditionalOnDiscoveryEnabled}).</li>
* <li>The Reactive Discovery is explicitly enabled ({@link ConditionalOnReactiveDiscoveryEnabled}).</li>
* <li>The Reactive Discovery Client class is present on the classpath.</li>
* </ul>
*
* <h3>Example Usage:</h3>
* <pre>{@code
* @Configuration
* public class ReactiveDiscoveryConfig {
*
* @Bean
* @ConditionalOnReactiveDiscoveryAvailable
* public MyReactiveService myReactiveService(ReactiveDiscoveryClient client) {
* return new MyReactiveService(client);
* }
* }
* }</pre>
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Documented
@Inherited
@ConditionalOnClass(name = {
REACTIVE_DISCOVERY_CLIENT_CLASS_NAME
})
@ConditionalOnDiscoveryEnabled
@ConditionalOnReactiveDiscoveryEnabled
public @interface ConditionalOnReactiveDiscoveryAvailable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.cloud.client.CommonsClientAutoConfiguration;
import org.springframework.cloud.client.ReactiveCommonsClientAutoConfiguration;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.cloud.client.discovery.composite.reactive.ReactiveCompositeDiscoveryClientAutoConfiguration;
import org.springframework.cloud.client.discovery.simple.reactive.SimpleReactiveDiscoveryClientAutoConfiguration;
Expand All @@ -38,6 +39,13 @@ public interface DiscoveryClientConstants {
*/
String DISCOVERY_CLIENT_CLASS_NAME = "org.springframework.cloud.client.discovery.DiscoveryClient";

/**
* The class name of {@link ReactiveDiscoveryClient}
*
* @see org.springframework.cloud.client.discovery.ReactiveDiscoveryClient
*/
String REACTIVE_DISCOVERY_CLIENT_CLASS_NAME = "org.springframework.cloud.client.discovery.ReactiveDiscoveryClient";

/**
* The class name of {@link CompositeDiscoveryClient}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@
*/
package io.microsphere.spring.cloud.client.service.registry.autoconfigure;

import io.microsphere.spring.boot.webflux.autoconfigure.condition.ConditionalOnWebFluxAvailable;
import io.microsphere.spring.cloud.client.service.registry.condition.ConditionalOnAutoServiceRegistrationAvailable;
import io.microsphere.spring.web.metadata.WebEndpointMapping;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;

import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type.REACTIVE;

/**
* Auto-Configuration class for {@link ServiceRegistry ServiceRegistry} on the Spring WebFlux Application
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@ConditionalOnWebApplication(type = REACTIVE)
@ConditionalOnWebFluxAvailable
@ConditionalOnAutoServiceRegistrationAvailable
@AutoConfigureAfter(value = {
ServiceRegistryAutoConfiguration.class
}, name = {
"io.microsphere.spring.boot.webflux.autoconfigure.WebFluxAutoConfiguration"
})
public class WebFluxServiceRegistryAutoConfiguration extends WebServiceRegistryAutoConfiguration {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
*/
package io.microsphere.spring.cloud.client.service.registry.autoconfigure;

import io.microsphere.spring.boot.webmvc.autoconfigure.condition.ConditionalOnWebMvcAvailable;
import io.microsphere.spring.cloud.client.service.registry.condition.ConditionalOnAutoServiceRegistrationAvailable;
import io.microsphere.spring.web.metadata.WebEndpointMapping;
import io.microsphere.util.ValueHolder;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletRegistrationBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
Expand All @@ -33,15 +35,20 @@
import static io.microsphere.util.ArrayUtils.EMPTY_STRING_ARRAY;
import static io.microsphere.util.ArrayUtils.arrayEquals;
import static java.lang.Boolean.FALSE;
import static org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type.SERVLET;

/**
* Auto-Configuration class for {@link ServiceRegistry ServiceRegistry} on the Spring WebMVC Application
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @since 1.0.0
*/
@ConditionalOnWebApplication(type = SERVLET)
@ConditionalOnWebMvcAvailable
@ConditionalOnAutoServiceRegistrationAvailable
@AutoConfigureAfter(value = {
ServiceRegistryAutoConfiguration.class
}, name = {
"io.microsphere.spring.boot.webmvc.autoconfigure.WebMvcAutoConfiguration"
})
public class WebMvcServiceRegistryAutoConfiguration extends WebServiceRegistryAutoConfiguration {

private static final String[] DEFAULT_URL_MAPPINGS = {"/*"};
Expand Down
Loading
Loading