mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-12-12 04:09:28 +08:00
⚡ 拆分blade-tool,引入blade-core-cloud
This commit is contained in:
parent
6daec7a2ce
commit
8222bcac25
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -31,16 +31,17 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-cache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<!-- Blade -->
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-launch</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-cloud</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-tool</artifactId>
|
||||
|
@ -15,14 +15,9 @@
|
||||
*/
|
||||
package org.springblade.core.boot.config;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.boot.feign.BladeFeignRequestHeaderInterceptor;
|
||||
import org.springblade.core.boot.feign.FeignHystrixConcurrencyStrategy;
|
||||
import org.springblade.core.boot.resolver.TokenArgumentResolver;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@ -46,15 +41,4 @@ public class BladeWebMvcConfiguration implements WebMvcConfigurer {
|
||||
argumentResolvers.add(new TokenArgumentResolver());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RequestInterceptor requestInterceptor() {
|
||||
return new BladeFeignRequestHeaderInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FeignHystrixConcurrencyStrategy feignHystrixConcurrencyStrategy() {
|
||||
return new FeignHystrixConcurrencyStrategy();
|
||||
}
|
||||
|
||||
}
|
||||
|
72
blade-core-cloud/pom.xml
Normal file
72
blade-core-cloud/pom.xml
Normal file
@ -0,0 +1,72 @@
|
||||
<?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>blade-tool</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blade-core-cloud</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>${blade.tool.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-undertow</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||
<version>${spring.boot.admin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
</dependency>-->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.springblade.core.cloud.config;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.cloud.feign.BladeFeignRequestHeaderInterceptor;
|
||||
import org.springblade.core.cloud.feign.FeignHystrixConcurrencyStrategy;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* WEB配置
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class BladeFeignConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RequestInterceptor requestInterceptor() {
|
||||
return new BladeFeignRequestHeaderInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FeignHystrixConcurrencyStrategy feignHystrixConcurrencyStrategy() {
|
||||
return new FeignHystrixConcurrencyStrategy();
|
||||
}
|
||||
|
||||
}
|
@ -13,12 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springblade.core.boot.feign;
|
||||
package org.springblade.core.cloud.feign;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.secure.utils.SecureUtil;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@ -43,7 +42,7 @@ public class BladeFeignRequestHeaderInterceptor implements RequestInterceptor {
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String name = headerNames.nextElement();
|
||||
String value = request.getHeader(name);
|
||||
if (SecureUtil.HEADER.equals(name)) {
|
||||
if ("blade-auth".equals(name)) {
|
||||
requestTemplate.header(name, value);
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springblade.core.boot.feign;
|
||||
package org.springblade.core.cloud.feign;
|
||||
|
||||
import com.netflix.hystrix.HystrixThreadPoolKey;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -1,54 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.springblade.core.launch.config;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import org.springblade.core.launch.consul.BladeConsulServiceRegistry;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.cloud.consul.ConditionalOnConsulEnabled;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.cloud.consul.discovery.TtlScheduler;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistryAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Consul自定义注册规则
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnConsulEnabled
|
||||
@AutoConfigureBefore(ConsulServiceRegistryAutoConfiguration.class)
|
||||
public class BladeConsulServiceRegistryConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
private TtlScheduler ttlScheduler;
|
||||
|
||||
@Autowired
|
||||
private ServerInfo serverInfo;
|
||||
|
||||
@Bean
|
||||
public ConsulServiceRegistry consulServiceRegistry(ConsulClient consulClient, ConsulDiscoveryProperties properties,
|
||||
HeartbeatProperties heartbeatProperties) {
|
||||
return new BladeConsulServiceRegistry(consulClient, properties, ttlScheduler, heartbeatProperties, serverInfo);
|
||||
}
|
||||
|
||||
}
|
@ -17,11 +17,7 @@ package org.springblade.core.launch.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springblade.core.launch.props.BladeProperties;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@ -39,16 +35,4 @@ import org.springframework.core.annotation.Order;
|
||||
})
|
||||
public class BladeLaunchConfiguration {
|
||||
|
||||
private ServerProperties serverProperties;
|
||||
private InetUtils inetUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 服务器信息
|
||||
*/
|
||||
@Bean
|
||||
public ServerInfo serverInfo() {
|
||||
return new ServerInfo(serverProperties, inetUtils);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.springblade.core.launch.consul;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import org.springblade.core.launch.server.ServerInfo;
|
||||
import org.springframework.cloud.consul.discovery.ConsulDiscoveryProperties;
|
||||
import org.springframework.cloud.consul.discovery.HeartbeatProperties;
|
||||
import org.springframework.cloud.consul.discovery.TtlScheduler;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulRegistration;
|
||||
import org.springframework.cloud.consul.serviceregistry.ConsulServiceRegistry;
|
||||
|
||||
/**
|
||||
* Consul自定义注册规则
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class BladeConsulServiceRegistry extends ConsulServiceRegistry {
|
||||
|
||||
private ServerInfo serverInfo;
|
||||
|
||||
public BladeConsulServiceRegistry(ConsulClient client, ConsulDiscoveryProperties properties, TtlScheduler ttlScheduler, HeartbeatProperties heartbeatProperties, ServerInfo serverInfo) {
|
||||
super(client, properties, ttlScheduler, heartbeatProperties);
|
||||
this.serverInfo = serverInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(ConsulRegistration reg) {
|
||||
reg.getService().setId(reg.getService().getName() + "-" + serverInfo.getIP() + "-" + serverInfo.getPort());
|
||||
super.register(reg);
|
||||
}
|
||||
|
||||
}
|
@ -15,53 +15,37 @@
|
||||
*/
|
||||
package org.springblade.core.launch.server;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.springblade.core.launch.utils.INetUtil;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 服务器信息
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class ServerInfo {
|
||||
|
||||
private ServerProperties serverProperties;
|
||||
private InetUtils inetUtils;
|
||||
@Getter
|
||||
@Configuration
|
||||
public class ServerInfo implements SmartInitializingSingleton {
|
||||
private final ServerProperties serverProperties;
|
||||
private String hostName;
|
||||
private String ip;
|
||||
private Integer port;
|
||||
private String ipWithPort;
|
||||
|
||||
public ServerInfo(ServerProperties serverProperties, InetUtils inetUtils) {
|
||||
@Autowired(required = false)
|
||||
public ServerInfo(ServerProperties serverProperties) {
|
||||
this.serverProperties = serverProperties;
|
||||
this.inetUtils = inetUtils;
|
||||
this.hostName = getHostInfo().getHostname();
|
||||
this.ip = getHostInfo().getIpAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
this.hostName = INetUtil.getHostName();
|
||||
this.ip = INetUtil.getHostIp();
|
||||
this.port = serverProperties.getPort();
|
||||
this.ipWithPort = String.format("%s:%d", ip, port);
|
||||
}
|
||||
|
||||
public InetUtils.HostInfo getHostInfo() {
|
||||
return inetUtils.findFirstNonLoopbackHostInfo();
|
||||
}
|
||||
|
||||
public String getIP() {
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public String getHostName() {
|
||||
return this.hostName;
|
||||
}
|
||||
|
||||
public String getIPWithPort() {
|
||||
return this.ipWithPort;
|
||||
}
|
||||
|
||||
public ServerProperties getServerProperties() {
|
||||
return this.serverProperties;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,156 @@
|
||||
/**
|
||||
* Copyright (c) 2019-2029, DreamLu 卢春梦 (596392912@qq.com & www.dreamlu.net).
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.springblade.core.launch.utils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* INet 相关工具
|
||||
*
|
||||
* @author L.cm
|
||||
*/
|
||||
public class INetUtil {
|
||||
public static final String LOCAL_HOST = "127.0.0.1";
|
||||
|
||||
/**
|
||||
* 获取 服务器 hostname
|
||||
*
|
||||
* @return hostname
|
||||
*/
|
||||
public static String getHostName() {
|
||||
String hostname;
|
||||
try {
|
||||
InetAddress address = InetAddress.getLocalHost();
|
||||
// force a best effort reverse DNS lookup
|
||||
hostname = address.getHostName();
|
||||
if (hostname == null || "".equals(hostname)) {
|
||||
hostname = address.toString();
|
||||
}
|
||||
} catch (UnknownHostException ignore) {
|
||||
hostname = LOCAL_HOST;
|
||||
}
|
||||
return hostname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 服务器 HostIp
|
||||
*
|
||||
* @return HostIp
|
||||
*/
|
||||
public static String getHostIp() {
|
||||
String hostAddress;
|
||||
try {
|
||||
InetAddress address = INetUtil.getLocalHostLANAddress();
|
||||
// force a best effort reverse DNS lookup
|
||||
hostAddress = address.getHostAddress();
|
||||
if (hostAddress == null || "".equals(hostAddress)) {
|
||||
hostAddress = address.toString();
|
||||
}
|
||||
} catch (UnknownHostException ignore) {
|
||||
hostAddress = LOCAL_HOST;
|
||||
}
|
||||
return hostAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java
|
||||
*
|
||||
* <p>
|
||||
* Returns an <code>InetAddress</code> object encapsulating what is most likely the machine's LAN IP address.
|
||||
* <p/>
|
||||
* This method is intended for use as a replacement of JDK method <code>InetAddress.getLocalHost</code>, because
|
||||
* that method is ambiguous on Linux systems. Linux systems enumerate the loopback network interface the same
|
||||
* way as regular LAN network interfaces, but the JDK <code>InetAddress.getLocalHost</code> method does not
|
||||
* specify the algorithm used to select the address returned under such circumstances, and will often return the
|
||||
* loopback address, which is not valid for network communication. Details
|
||||
* <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037">here</a>.
|
||||
* <p/>
|
||||
* This method will scan all IP addresses on all network interfaces on the host machine to determine the IP address
|
||||
* most likely to be the machine's LAN address. If the machine has multiple IP addresses, this method will prefer
|
||||
* a site-local IP address (e.g. 192.168.x.x or 10.10.x.x, usually IPv4) if the machine has one (and will return the
|
||||
* first site-local address if the machine has more than one), but if the machine does not hold a site-local
|
||||
* address, this method will return simply the first non-loopback address found (IPv4 or IPv6).
|
||||
* <p/>
|
||||
* If this method cannot find a non-loopback address using this selection algorithm, it will fall back to
|
||||
* calling and returning the result of JDK method <code>InetAddress.getLocalHost</code>.
|
||||
* <p/>
|
||||
*
|
||||
* @throws UnknownHostException If the LAN address of the machine cannot be found.
|
||||
*/
|
||||
private static InetAddress getLocalHostLANAddress() throws UnknownHostException {
|
||||
try {
|
||||
InetAddress candidateAddress = null;
|
||||
// Iterate all NICs (network interface cards)...
|
||||
for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements(); ) {
|
||||
NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
|
||||
// Iterate all IP addresses assigned to each card...
|
||||
for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements(); ) {
|
||||
InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
|
||||
if (!inetAddr.isLoopbackAddress()) {
|
||||
|
||||
if (inetAddr.isSiteLocalAddress()) {
|
||||
// Found non-loopback site-local address. Return it immediately...
|
||||
return inetAddr;
|
||||
} else if (candidateAddress == null) {
|
||||
// Found non-loopback address, but not necessarily site-local.
|
||||
// Store it as a candidate to be returned if site-local address is not subsequently found...
|
||||
candidateAddress = inetAddr;
|
||||
// Note that we don't repeatedly assign non-loopback non-site-local addresses as candidates,
|
||||
// only the first. For subsequent iterations, candidate will be non-null.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (candidateAddress != null) {
|
||||
// We did not find a site-local address, but we found some other non-loopback address.
|
||||
// Server might have a non-site-local address assigned to its NIC (or it might be running
|
||||
// IPv6 which deprecates the "site-local" concept).
|
||||
// Return this non-loopback candidate address...
|
||||
return candidateAddress;
|
||||
}
|
||||
// At this point, we did not find a non-loopback address.
|
||||
// Fall back to returning whatever InetAddress.getLocalHost() returns...
|
||||
InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
|
||||
if (jdkSuppliedAddress == null) {
|
||||
throw new UnknownHostException("The JDK InetAddress.getLocalHost() method unexpectedly returned null.");
|
||||
}
|
||||
return jdkSuppliedAddress;
|
||||
} catch (Exception e) {
|
||||
UnknownHostException unknownHostException = new UnknownHostException("Failed to determine LAN address: " + e);
|
||||
unknownHostException.initCause(e);
|
||||
throw unknownHostException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试端口时候被占用
|
||||
*
|
||||
* @param port 端口号
|
||||
* @return 没有被占用:true,被占用:false
|
||||
*/
|
||||
public static boolean tryPort(int port) {
|
||||
try (ServerSocket ignore = new ServerSocket(port)) {
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -27,23 +27,17 @@
|
||||
<artifactId>blade-core-secure</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-cloud</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<!--Mybatis-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus</artifactId>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
</dependency>
|
||||
<!--Feign-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -60,7 +60,7 @@ public class ApiLogListener {
|
||||
HttpServletRequest request = (HttpServletRequest) source.get(EventConstant.EVENT_REQUEST);
|
||||
logApi.setServiceId(bladeProperties.getName());
|
||||
logApi.setServerHost(serverInfo.getHostName());
|
||||
logApi.setServerIp(serverInfo.getIPWithPort());
|
||||
logApi.setServerIp(serverInfo.getIpWithPort());
|
||||
logApi.setEnv(bladeProperties.getEnv());
|
||||
logApi.setRemoteIp(WebUtil.getIP(request));
|
||||
logApi.setUserAgent(request.getHeader(WebUtil.USER_AGENT_HEADER));
|
||||
|
@ -60,7 +60,7 @@ public class ErrorLogListener {
|
||||
logError.setParams(WebUtil.getRequestParamString(request));
|
||||
logError.setServiceId(bladeProperties.getName());
|
||||
logError.setServerHost(serverInfo.getHostName());
|
||||
logError.setServerIp(serverInfo.getIPWithPort());
|
||||
logError.setServerIp(serverInfo.getIpWithPort());
|
||||
logError.setEnv(bladeProperties.getEnv());
|
||||
logError.setCreateBy(SecureUtil.getUserAccount(request));
|
||||
logError.setCreateTime(LocalDateTime.now());
|
||||
|
@ -63,7 +63,7 @@ public class UsualLogListener {
|
||||
logUsual.setServerHost(serverInfo.getHostName());
|
||||
logUsual.setServiceId(bladeProperties.getName());
|
||||
logUsual.setEnv(bladeProperties.getEnv());
|
||||
logUsual.setServerIp(serverInfo.getIPWithPort());
|
||||
logUsual.setServerIp(serverInfo.getIpWithPort());
|
||||
logUsual.setCreateBy(SecureUtil.getUserAccount(request));
|
||||
logUsual.setCreateTime(LocalDateTime.now());
|
||||
logService.saveUsualLog(logUsual);
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -18,7 +18,6 @@ package org.springblade.core.swagger;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -29,7 +28,6 @@ import java.util.List;
|
||||
* @author Chill
|
||||
*/
|
||||
@Data
|
||||
@RefreshScope
|
||||
@ConfigurationProperties("swagger")
|
||||
public class SwaggerProperties {
|
||||
/**
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -23,11 +23,6 @@
|
||||
<artifactId>blade-core-launch</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<!-- Cloud -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
|
35
pom.xml
35
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-tool</artifactId>
|
||||
<version>1.0.0-RC6</version>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>blade-tool</name>
|
||||
<description>
|
||||
@ -36,7 +36,7 @@
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<blade.tool.version>1.0.0-RC6</blade.tool.version>
|
||||
<blade.tool.version>1.0.0</blade.tool.version>
|
||||
|
||||
<java.version>1.8</java.version>
|
||||
<maven.plugin.version>3.8.0</maven.plugin.version>
|
||||
@ -48,7 +48,7 @@
|
||||
<protostuff.version>1.6.0</protostuff.version>
|
||||
<disruptor.version>3.4.2</disruptor.version>
|
||||
<spring.boot.admin.version>2.0.2</spring.boot.admin.version>
|
||||
<mica.auto.version>1.0.0</mica.auto.version>
|
||||
<mica.auto.version>1.0.1</mica.auto.version>
|
||||
|
||||
<spring.boot.version>2.0.7.RELEASE</spring.boot.version>
|
||||
<spring.cloud.version>Finchley.SR2</spring.cloud.version>
|
||||
@ -66,6 +66,7 @@
|
||||
<module>blade-core-log</module>
|
||||
<module>blade-core-mybatis</module>
|
||||
<module>blade-core-swagger</module>
|
||||
<module>blade-core-cloud</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -104,11 +105,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||
<version>${spring.boot.admin.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
@ -118,24 +114,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.retry</groupId>
|
||||
<artifactId>spring-retry</artifactId>
|
||||
@ -156,11 +134,6 @@
|
||||
<version>${mica.auto.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-indexer</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
Loading…
Reference in New Issue
Block a user