-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* change clientId algorithm * code format * develop * optimize on 2.0.5.EINSITANG * revert pom version * change note * change note * revert demo.rocketmq.myNameServer * remove clientInstaceName * remove unuse method * pass ci-check * remove pass annotation * correct variable word * optimize annotation * merge Co-authored-by: von gosling <vongosling@apache.org>
- Loading branch information
1 parent
c7f230f
commit 2853384
Showing
4 changed files
with
79 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/SpringBeanUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.rocketmq.spring.support; | ||
|
||
import org.springframework.aop.scope.ScopedProxyUtils; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.lang.NonNull; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class SpringBeanUtil { | ||
|
||
/** | ||
* Override applicationContext.getBeansWithAnnotation method to make sure without same ProxyTarget beans | ||
* | ||
* @param applicationContext spring Application Context | ||
* @param clazz annotation class | ||
* @return beans map without proxyTarget bean | ||
*/ | ||
public static Map<String, Object> getBeansWithAnnotation(@NonNull ConfigurableApplicationContext applicationContext, Class<? extends Annotation> clazz) { | ||
Map<String, Object> beans = applicationContext.getBeansWithAnnotation(clazz); | ||
Map<String, Object> filterBeans = new HashMap<>(beans.size()); | ||
// remove proxy target | ||
Set<Map.Entry<String, Object>> entrySet = beans.entrySet(); | ||
entrySet.forEach((entry) -> { | ||
final String beanName = entry.getKey(); | ||
if (!ScopedProxyUtils.isScopedTarget(beanName)) { | ||
filterBeans.put(beanName, entry.getValue()); | ||
} | ||
}); | ||
return filterBeans; | ||
} | ||
|
||
} |