-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* avoid npe (#1177) Co-authored-by: 致节 <hzj266771@antgroup.com> (cherry picked from commit 7e5fd1e) * Add annotation sofa service bean (#1176) (cherry picked from commit 123b3eb) * straight application listener order (#1179) (cherry picked from commit bb45ec7) --------- Co-authored-by: Dando <jialindeng7@163.com>
- Loading branch information
1 parent
50ee113
commit 6b77bb7
Showing
9 changed files
with
203 additions
and
6 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
61 changes: 61 additions & 0 deletions
61
...ntime-sofa-boot/src/main/java/com/alipay/sofa/runtime/api/annotation/SofaServiceBean.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,61 @@ | ||
/* | ||
* 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 com.alipay.sofa.runtime.api.annotation; | ||
|
||
import org.springframework.core.annotation.AliasFor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation used to create a SOFA service, which will also be created as a bean. | ||
* Sample usage: | ||
* | ||
* <pre> | ||
* | ||
* @SofaServiceBean(uniqueId = "aop") | ||
* public class SampleServiceImpl implements SampleService { | ||
* | ||
* @Override | ||
* public String say() { | ||
* return "sampleService"; | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* @author xunfang 23/5/23 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@SofaService | ||
@Component | ||
public @interface SofaServiceBean { | ||
@AliasFor(annotation = Component.class) | ||
String value() default ""; | ||
|
||
@AliasFor(annotation = SofaService.class) | ||
Class<?> interfaceType() default void.class; | ||
|
||
@AliasFor(annotation = SofaService.class) | ||
String uniqueId() default ""; | ||
|
||
@AliasFor(annotation = SofaService.class) | ||
SofaServiceBinding[] bindings() default { @SofaServiceBinding }; | ||
} |
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
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
.../sofa-boot/src/main/java/com/alipay/sofa/boot/util/ApplicationListenerOrderConstants.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 com.alipay.sofa.boot.util; | ||
|
||
import org.springframework.boot.context.logging.LoggingApplicationListener; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* ApplicationListener 顺序常量 | ||
* | ||
* @author xunfang | ||
* @version ApplicationListenerOrderConstants.java, v 0.1 2023/6/1 | ||
*/ | ||
public class ApplicationListenerOrderConstants { | ||
/** | ||
* 必须最先执行 | ||
*/ | ||
public static final int SOFA_BOOTSTRAP_RUN_LISTENER_ORDER = Ordered.HIGHEST_PRECEDENCE; | ||
|
||
/** | ||
* 必须在其他会触发 sofa-common-tools 日志上下文初始化的组件之前 | ||
*/ | ||
public static final int LOG_ENVIRONMENT_PREPARING_LISTENER_ORDER = Ordered.HIGHEST_PRECEDENCE + 12; | ||
|
||
/** | ||
* 必须在 LogEnvironmentPreparingListener 之后, 且 LoggingApplicationListener 之前 | ||
*/ | ||
public static final int SOFA_CONFIG_SOURCE_SUPPORT_LISTENER_ORDER = LOG_ENVIRONMENT_PREPARING_LISTENER_ORDER + 3; | ||
|
||
public static final int SOFA_TRACER_CONFIGURATION_LISTENER_ORDER = Ordered.HIGHEST_PRECEDENCE + 50; | ||
|
||
static { | ||
Assert.isTrue( | ||
SOFA_CONFIG_SOURCE_SUPPORT_LISTENER_ORDER < LoggingApplicationListener.DEFAULT_ORDER, | ||
"SofaConfigSourceSupportListener must init after LogEnvironmentPostProcessor"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...untime/src/main/java/com/alipay/sofa/smoke/tests/runtime/impl/SofaServiceBeanService.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,34 @@ | ||
/* | ||
* 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 com.alipay.sofa.smoke.tests.runtime.impl; | ||
|
||
import com.alipay.sofa.runtime.api.annotation.SofaServiceBean; | ||
import com.alipay.sofa.smoke.tests.runtime.service.SampleService; | ||
|
||
/** | ||
* SofaServiceBeanService | ||
* | ||
* @author xunfang | ||
* @version SofaServiceBeanService.java, v 0.1 2023/5/23 | ||
*/ | ||
@SofaServiceBean(value = "sofaServiceBeanService", uniqueId = "sofaServiceBeanService") | ||
public class SofaServiceBeanService implements SampleService { | ||
@Override | ||
public String service() { | ||
return "sofaServiceBeanService"; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../test/java/com/alipay/sofa/smoke/tests/runtime/spring/SofaServiceBeanAnnotationTests.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,45 @@ | ||
/* | ||
* 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 com.alipay.sofa.smoke.tests.runtime.spring; | ||
|
||
import com.alipay.sofa.runtime.api.annotation.SofaReference; | ||
import com.alipay.sofa.smoke.tests.runtime.RuntimeSofaBootApplication; | ||
import com.alipay.sofa.smoke.tests.runtime.service.SampleService; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* SofaServiceBeanAnnotationTests | ||
* | ||
* @author xunfang | ||
* @version SofaServiceBeanAnnotationTests.java, v 0.1 2023/5/23 | ||
*/ | ||
@SpringBootTest(classes = RuntimeSofaBootApplication.class) | ||
public class SofaServiceBeanAnnotationTests { | ||
|
||
@SofaReference(uniqueId = "sofaServiceBeanService") | ||
private SampleService sofaServiceBeanService; | ||
|
||
@Test | ||
public void testSofaServiceBean() { | ||
assertThat(sofaServiceBeanService).isNotNull(); | ||
assertThat("sofaServiceBeanService").isEqualTo(sofaServiceBeanService.service()); | ||
} | ||
|
||
} |