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
2 changes: 2 additions & 0 deletions .artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ dubbo-spring-boot-actuator-autoconfigure
dubbo-spring-boot-actuator-compatible
dubbo-spring-boot-autoconfigure
dubbo-spring-boot-3-autoconfigure
dubbo-spring-boot-4-autoconfigure
dubbo-spring-boot-autoconfigure-compatible
dubbo-spring-boot-actuator-autoconfigure-compatible
dubbo-spring-boot-compatible
Expand All @@ -103,6 +104,7 @@ dubbo-tracing-otel-zipkin-spring-boot-starter
dubbo-tracing-otel-otlp-spring-boot-starter
dubbo-observability-spring-boot-starter
dubbo-spring-boot-starter
dubbo-spring-boot-starter4
dubbo-spring-boot-starters
dubbo-spring-boot-interceptor
dubbo-nacos-spring-boot-starter
Expand Down
10 changes: 10 additions & 0 deletions dubbo-distribution/dubbo-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@
<artifactId>dubbo-spring-boot-3-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-4-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-compatible</artifactId>
Expand All @@ -519,6 +524,11 @@
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@

public class SpringBoot3Condition implements Condition {

public static boolean IS_SPRING_BOOT_3 = SpringBootVersion.getVersion().charAt(0) >= '3';
public static boolean IS_SPRING_BOOT_3 = getSpringBootMajorVersion() == 3;

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return IS_SPRING_BOOT_3;
}

private static int getSpringBootMajorVersion() {
String version = SpringBootVersion.getVersion();
if (version == null || version.isEmpty()) {
return -1;
}
int separator = version.indexOf('.');
String majorVersion = separator < 0 ? version : version.substring(0, separator);
try {
return Integer.parseInt(majorVersion);
} catch (NumberFormatException ignored) {
return -1;
}
}
}
119 changes: 119 additions & 0 deletions dubbo-spring-boot-project/dubbo-spring-boot-4-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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>org.apache.dubbo</groupId>
<artifactId>dubbo-parent</artifactId>
<version>${revision}</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>dubbo-spring-boot-4-autoconfigure</artifactId>
<packaging>jar</packaging>
<description>Apache Dubbo Spring Boot 4 Auto-Configure</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot-4.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Spring Boot dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-tomcat</artifactId>
<optional>true</optional>
</dependency>

<!-- Dubbo -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-servlet</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-triple-websocket</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.websocket</groupId>
<artifactId>jakarta.websocket-client-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>17</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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 org.apache.dubbo.spring.boot.autoconfigure;

import org.apache.dubbo.rpc.protocol.tri.ServletExchanger;
import org.apache.dubbo.rpc.protocol.tri.servlet.jakarta.TripleFilter;
import org.apache.dubbo.rpc.protocol.tri.websocket.jakarta.TripleWebSocketFilter;

import jakarta.servlet.Filter;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.UpgradeProtocol;
import org.apache.coyote.http2.Http2Protocol;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.tomcat.ConfigurableTomcatWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
@Conditional(SpringBoot4Condition.class)
public class DubboTriple4AutoConfiguration {

public static final String SERVLET_PREFIX = "dubbo.protocol.triple.servlet";

public static final String WEBSOCKET_PREFIX = "dubbo.protocol.triple.websocket";

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Filter.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnProperty(prefix = SERVLET_PREFIX, name = "enabled", havingValue = "true")
public static class TripleServletConfiguration {

@Bean
public FilterRegistrationBean<TripleFilter> tripleProtocolFilter(
@Value("${" + SERVLET_PREFIX + ".filter-url-patterns:/*}") String[] urlPatterns,
@Value("${" + SERVLET_PREFIX + ".filter-order:-1000000}") int order,
@Value("${server.port:8080}") int serverPort) {
ServletExchanger.bindServerPort(serverPort);
FilterRegistrationBean<TripleFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new TripleFilter());
registrationBean.addUrlPatterns(urlPatterns);
registrationBean.setOrder(order);
return registrationBean;
}

@Bean
@ConditionalOnClass(Http2Protocol.class)
@ConditionalOnProperty(prefix = SERVLET_PREFIX, name = "max-concurrent-streams")
public WebServerFactoryCustomizer<ConfigurableTomcatWebServerFactory> tripleTomcatHttp2Customizer(
@Value("${" + SERVLET_PREFIX + ".max-concurrent-streams}") int maxConcurrentStreams) {
return factory -> factory.addConnectorCustomizers(connector -> {
ProtocolHandler handler = connector.getProtocolHandler();
for (UpgradeProtocol upgradeProtocol : handler.findUpgradeProtocols()) {
if (upgradeProtocol instanceof Http2Protocol) {
Http2Protocol protocol = (Http2Protocol) upgradeProtocol;
int value = maxConcurrentStreams <= 0 ? Integer.MAX_VALUE : maxConcurrentStreams;
protocol.setMaxConcurrentStreams(value);
protocol.setMaxConcurrentStreamExecution(value);
}
}
});
}
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(Filter.class)
@ConditionalOnWebApplication(type = Type.SERVLET)
@ConditionalOnProperty(prefix = WEBSOCKET_PREFIX, name = "enabled", havingValue = "true")
public static class TripleWebSocketConfiguration {

@Bean
public FilterRegistrationBean<TripleWebSocketFilter> tripleWebSocketFilter(
@Value("${" + WEBSOCKET_PREFIX + ".filter-url-patterns:/*}") String[] urlPatterns,
@Value("${" + WEBSOCKET_PREFIX + ".filter-order:-1000000}") int order,
@Value("${server.port:8080}") int serverPort) {
ServletExchanger.bindServerPort(serverPort);
FilterRegistrationBean<TripleWebSocketFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new TripleWebSocketFilter());
registrationBean.addUrlPatterns(urlPatterns);
registrationBean.setOrder(order);
return registrationBean;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 org.apache.dubbo.spring.boot.autoconfigure;

import org.springframework.boot.SpringBootVersion;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class SpringBoot4Condition implements Condition {

public static boolean IS_SPRING_BOOT_4 = getSpringBootMajorVersion() >= 4;

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return IS_SPRING_BOOT_4;
}

private static int getSpringBootMajorVersion() {
String version = SpringBootVersion.getVersion();
if (version == null || version.isEmpty()) {
return -1;
}
int separator = version.indexOf('.');
String majorVersion = separator < 0 ? version : version.substring(0, separator);
try {
return Integer.parseInt(majorVersion);
} catch (NumberFormatException ignored) {
return -1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.apache.dubbo.spring.boot.autoconfigure.DubboTriple4AutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.dubbo.spring.boot.autoconfigure.DubboTriple4AutoConfiguration
Loading
Loading