diff --git a/springboot-samples/aop/Formatter.xml b/springboot-samples/aop/Formatter.xml new file mode 100644 index 00000000..1dc90544 --- /dev/null +++ b/springboot-samples/aop/Formatter.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-samples/aop/HEADER b/springboot-samples/aop/HEADER new file mode 100644 index 00000000..1745cfe6 --- /dev/null +++ b/springboot-samples/aop/HEADER @@ -0,0 +1,14 @@ +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. diff --git a/springboot-samples/aop/base-aop/Formatter.xml b/springboot-samples/aop/base-aop/Formatter.xml new file mode 100644 index 00000000..1dc90544 --- /dev/null +++ b/springboot-samples/aop/base-aop/Formatter.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-samples/aop/base-aop/HEADER b/springboot-samples/aop/base-aop/HEADER new file mode 100644 index 00000000..1745cfe6 --- /dev/null +++ b/springboot-samples/aop/base-aop/HEADER @@ -0,0 +1,14 @@ +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. diff --git a/springboot-samples/aop/base-aop/pom.xml b/springboot-samples/aop/base-aop/pom.xml new file mode 100644 index 00000000..6b8ac2b2 --- /dev/null +++ b/springboot-samples/aop/base-aop/pom.xml @@ -0,0 +1,102 @@ + + + 4.0.0 + + com.alipay.sofa.aop + aop + 0.0.1-SNAPSHOT + ../pom.xml + + base-aop + 0.0.1-SNAPSHOT + base-aop + base for aop + + + + + com.alipay.sofa.aop + base-common + 0.0.1-SNAPSHOT + + + com.alipay.sofa.koupleless + koupleless-base-starter + ${koupleless.runtime.version} + + + com.alipay.sofa + web-ark-plugin + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-logging + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + repackage + + repackage + + + + + + + com.alipay.sofa.koupleless + koupleless-base-build-plugin + ${koupleless.runtime.version} + + + + add-patch + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + jar + + package + + lib + + + + + + + + + diff --git a/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/BaseApplication.java b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/BaseApplication.java new file mode 100644 index 00000000..6e36146c --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/BaseApplication.java @@ -0,0 +1,51 @@ +/* + * 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.aop.base; + +import ch.qos.logback.classic.ClassicConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.ImportResource; + +@ImportResource({ "classpath*:META-INF/spring/service.xml" }) +@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) +public class BaseApplication { + + static { + // 建议加到jvm 参数中 + // 需要保证在 slf4j static bind 之前,(如,首次 getLogger、类加载 SpringApplication 之前) + System.setProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR, + "com.alipay.sofa.ark.common.adapter.ArkLogbackContextSelector"); + } + + private static Logger LOGGER = LoggerFactory.getLogger(BaseApplication.class); + + public static void main(String[] args) { + ConfigurableApplicationContext context = SpringApplication.run(BaseApplication.class, args); + context.getBean("sampleService"); + LOGGER.info("BaseApplication start!"); + LOGGER.info("Spring Boot Version: " + + SpringApplication.class.getPackage().getImplementationVersion()); + LOGGER.info("BaseApplication classLoader: " + BaseApplication.class.getClassLoader()); + } +} diff --git a/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/facade/SampleService.java b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/facade/SampleService.java new file mode 100644 index 00000000..4acb72ec --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/facade/SampleService.java @@ -0,0 +1,26 @@ +/* + * 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.aop.base.facade; + +public interface SampleService { + + /** + * a simple facade + * @return + */ + String service(); +} diff --git a/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/impl/SampleServiceImpl.java b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/impl/SampleServiceImpl.java new file mode 100644 index 00000000..c741fc15 --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/impl/SampleServiceImpl.java @@ -0,0 +1,40 @@ +/* + * 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.aop.base.impl; + +import com.alipay.sofa.aop.base.facade.SampleService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; + +@Service +public class SampleServiceImpl implements SampleService { + private static Logger LOGGER = LoggerFactory.getLogger(SampleServiceImpl.class); + + @Autowired + private ApplicationContext applicationContext; + + @Override + public String service() { + String appName = applicationContext.getId(); + + LOGGER.info("{} web test: into a service", appName); + return "A Sample Service"; + } +} diff --git a/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/rest/SampleController.java b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/rest/SampleController.java new file mode 100644 index 00000000..e40bd6f6 --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/java/com/alipay/sofa/aop/base/rest/SampleController.java @@ -0,0 +1,49 @@ +/* + * 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.aop.base.rest; + +import com.alipay.sofa.aop.base.facade.SampleService; +import com.alipay.sofa.aop.base.common.conf.LogAround; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + private static Logger LOGGER = LoggerFactory.getLogger(SampleController.class); + + @Autowired + private ApplicationContext applicationContext; + + @Autowired + private SampleService sampleService; + + @LogAround(value = "run index in base") + @RequestMapping(value = "/", method = RequestMethod.GET) + public String hello() { + String appName = applicationContext.getId(); + LOGGER.info("{} web test: into sample controller", appName); + + sampleService.service(); + + return String.format("hello to %s deploy", appName); + } +} diff --git a/springboot-samples/aop/base-aop/src/main/resources/META-INF/spring/service.xml b/springboot-samples/aop/base-aop/src/main/resources/META-INF/spring/service.xml new file mode 100644 index 00000000..0a11035d --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/resources/META-INF/spring/service.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/springboot-samples/aop/base-aop/src/main/resources/application.properties b/springboot-samples/aop/base-aop/src/main/resources/application.properties new file mode 100644 index 00000000..3c524b18 --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=base +logging.file.path=./aop/logs/ diff --git a/springboot-samples/aop/base-aop/src/main/resources/logback-spring.xml b/springboot-samples/aop/base-aop/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..bd7018ea --- /dev/null +++ b/springboot-samples/aop/base-aop/src/main/resources/logback-spring.xml @@ -0,0 +1,35 @@ + + + + + + + + + ${appname} 000 %date %5level %6relative --- [%15thread] [%-40logger{40}] [%C:%L] : [%X{traceId:-0}] %msg%n + + + + true + + ${level} + + ${logging.file.path}/${appname}/app-default.log + + ${logging.file.path}/${appname}/app-default.log.%d{yyyy-MM-dd} + 30 + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-samples/aop/base-common/Formatter.xml b/springboot-samples/aop/base-common/Formatter.xml new file mode 100644 index 00000000..1dc90544 --- /dev/null +++ b/springboot-samples/aop/base-common/Formatter.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-samples/aop/base-common/HEADER b/springboot-samples/aop/base-common/HEADER new file mode 100644 index 00000000..1745cfe6 --- /dev/null +++ b/springboot-samples/aop/base-common/HEADER @@ -0,0 +1,14 @@ +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. diff --git a/springboot-samples/aop/base-common/pom.xml b/springboot-samples/aop/base-common/pom.xml new file mode 100644 index 00000000..a9f904d3 --- /dev/null +++ b/springboot-samples/aop/base-common/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + com.alipay.sofa.aop + aop + 0.0.1-SNAPSHOT + ../pom.xml + + base-common + 0.0.1-SNAPSHOT + + + + + com.alipay.sofa.koupleless + koupleless-base-starter + ${koupleless.runtime.version} + + + com.alipay.sofa + web-ark-plugin + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-aop + + + org.springframework.boot + spring-boot-starter-logging + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + + + jar + + package + + lib + + + + + + + + + diff --git a/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/AspectjConfiguration.java b/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/AspectjConfiguration.java new file mode 100644 index 00000000..8dd9c8e0 --- /dev/null +++ b/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/AspectjConfiguration.java @@ -0,0 +1,35 @@ +/* + * 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.aop.base.common.conf; + +import org.springframework.aop.Advisor; +import org.springframework.aop.aspectj.AspectJExpressionPointcut; +import org.springframework.aop.support.DefaultPointcutAdvisor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +@Configuration +@EnableAspectJAutoProxy +public class AspectjConfiguration { + @Bean + public Advisor advisor() { + AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); + pointcut.setExpression("@annotation(com.alipay.sofa.aop.base.common.conf.LogAround)"); + return new DefaultPointcutAdvisor(pointcut, new LogAroundInterceptor()); + } +} diff --git a/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/LogAround.java b/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/LogAround.java new file mode 100644 index 00000000..5fbdf258 --- /dev/null +++ b/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/LogAround.java @@ -0,0 +1,28 @@ +/* + * 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.aop.base.common.conf; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +public @interface LogAround { + String value() default ""; +} diff --git a/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/LogAroundInterceptor.java b/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/LogAroundInterceptor.java new file mode 100644 index 00000000..ab9326ca --- /dev/null +++ b/springboot-samples/aop/base-common/src/main/java/com/alipay/sofa/aop/base/common/conf/LogAroundInterceptor.java @@ -0,0 +1,59 @@ +/* + * 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.aop.base.common.conf; + +import lombok.extern.slf4j.Slf4j; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint; +import org.springframework.stereotype.Service; + +@Slf4j +@Aspect +@Service +public class LogAroundInterceptor implements MethodInterceptor { + + // 需要配合 advisor 使用 + @Override + public Object invoke(MethodInvocation methodInvocation) throws Throwable { + log.info("开始执行 in method invocation."); + LogAround anno = methodInvocation.getMethod().getAnnotation(LogAround.class); + if (anno != null) { + log.info("注解值为:{}", anno.value()); + } + Object o = methodInvocation.proceed(); + log.info("执行结束 in method invocation."); + return o; + } + + @Pointcut("@annotation(com.alipay.sofa.aop.base.common.conf.LogAround)") + public void pointcut() { + } + + // 模块扫描到 bean 即可执行 + @Around("pointcut()") + public Object around(ProceedingJoinPoint joinPoint) throws Throwable { + log.info("开始执行 in around"); + Object o = joinPoint.proceed(); + log.info("执行结束 in around"); + return o; + } +} diff --git a/springboot-samples/aop/biz1-aop/Formatter.xml b/springboot-samples/aop/biz1-aop/Formatter.xml new file mode 100644 index 00000000..1dc90544 --- /dev/null +++ b/springboot-samples/aop/biz1-aop/Formatter.xml @@ -0,0 +1,278 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-samples/aop/biz1-aop/HEADER b/springboot-samples/aop/biz1-aop/HEADER new file mode 100644 index 00000000..1745cfe6 --- /dev/null +++ b/springboot-samples/aop/biz1-aop/HEADER @@ -0,0 +1,14 @@ +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. diff --git a/springboot-samples/aop/biz1-aop/pom.xml b/springboot-samples/aop/biz1-aop/pom.xml new file mode 100644 index 00000000..8e6eea94 --- /dev/null +++ b/springboot-samples/aop/biz1-aop/pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + + com.alipay.sofa.aop + aop + 0.0.1-SNAPSHOT + ../pom.xml + + biz1-aop + 0.0.1-SNAPSHOT + biz1 + + + + com.alipay.sofa.aop + base-common + 0.0.1-SNAPSHOT + provided + + + org.springframework.boot + spring-boot-starter-web + provided + + + org.springframework.boot + spring-boot-starter-logging + provided + + + org.springframework.boot + spring-boot-starter-aop + provided + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alipay.sofa.koupleless + koupleless-app-starter + provided + + + + + + + com.alipay.sofa + sofa-ark-maven-plugin + ${sofa.ark.version} + + + default-cli + + repackage + + + + + true + ./target + biz1-aop + biz1 + true + + + + + + + + + diff --git a/springboot-samples/aop/biz1-aop/src/main/java/com/alipay/sofa/aop/biz1/Biz1Application.java b/springboot-samples/aop/biz1-aop/src/main/java/com/alipay/sofa/aop/biz1/Biz1Application.java new file mode 100644 index 00000000..d5f6c7e5 --- /dev/null +++ b/springboot-samples/aop/biz1-aop/src/main/java/com/alipay/sofa/aop/biz1/Biz1Application.java @@ -0,0 +1,41 @@ +/* + * 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.aop.biz1; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ComponentScans; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +@SpringBootApplication +@ComponentScans({ @ComponentScan("com.alipay.sofa.aop.base.common") }) +public class Biz1Application { + private static Logger LOGGER = LoggerFactory.getLogger(Biz1Application.class); + + public static void main(String[] args) { + SpringApplication.run(Biz1Application.class, args); + + LOGGER.info("BaseApplication start!"); + LOGGER.info("Spring Boot Version: " + + SpringApplication.class.getPackage().getImplementationVersion()); + LOGGER.info("BaseApplication classLoader: " + Biz1Application.class.getClassLoader()); + } + +} diff --git a/springboot-samples/aop/biz1-aop/src/main/java/com/alipay/sofa/aop/biz1/rest/SampleController.java b/springboot-samples/aop/biz1-aop/src/main/java/com/alipay/sofa/aop/biz1/rest/SampleController.java new file mode 100644 index 00000000..ab2c958a --- /dev/null +++ b/springboot-samples/aop/biz1-aop/src/main/java/com/alipay/sofa/aop/biz1/rest/SampleController.java @@ -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.aop.biz1.rest; + +import com.alipay.sofa.aop.base.common.conf.LogAround; +import com.alipay.sofa.koupleless.common.api.SpringBeanFinder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.lang.reflect.Method; + +@RestController +public class SampleController { + private static final Logger LOGGER = LoggerFactory.getLogger(SampleController.class); + + @Autowired + private ApplicationContext applicationContext; + + @LogAround(value = "run in biz") + @RequestMapping(value = "/", method = RequestMethod.GET) + public String hello() { + String appName = applicationContext.getId(); + LOGGER.info("{} web test: into sample controller", appName); + return String.format("hello to %s deploy", appName); + } +} diff --git a/springboot-samples/aop/biz1-aop/src/main/resources/application.properties b/springboot-samples/aop/biz1-aop/src/main/resources/application.properties new file mode 100644 index 00000000..eb4a5233 --- /dev/null +++ b/springboot-samples/aop/biz1-aop/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=biz1 +logging.file.path=./aop/logs/ diff --git a/springboot-samples/aop/biz1-aop/src/main/resources/logback-spring.xml b/springboot-samples/aop/biz1-aop/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..dbee2158 --- /dev/null +++ b/springboot-samples/aop/biz1-aop/src/main/resources/logback-spring.xml @@ -0,0 +1,36 @@ + + + + + + + + + + ${appname} 111 %date %5level %6relative --- [%15thread] [%-40logger{40}] [%C:%L] : [%X{traceId:-0}] %msg%n + + + + true + + ${level} + + ${logging.file.path}/${appname}/app-default.log + + ${logging.file.path}/${appname}/app-default.log.%d{yyyy-MM-dd} + 30 + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n + UTF-8 + + + + + + + + + + + \ No newline at end of file diff --git a/springboot-samples/aop/pom.xml b/springboot-samples/aop/pom.xml new file mode 100644 index 00000000..590f379a --- /dev/null +++ b/springboot-samples/aop/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + + com.alipay.sofa + springboot-samples + 0.0.1-SNAPSHOT + ../pom.xml + + com.alipay.sofa.aop + aop + 0.0.1-SNAPSHOT + pom + + + base-aop + biz1-aop + base-common + + diff --git a/springboot-samples/pom.xml b/springboot-samples/pom.xml index 23f45a19..c0706c90 100644 --- a/springboot-samples/pom.xml +++ b/springboot-samples/pom.xml @@ -40,6 +40,7 @@ logging/logback web/tomcat web/webflux + aop service slimming/log4j2 msg/kafka/base-kafka @@ -100,6 +101,11 @@ + + org.springframework.boot + spring-boot-starter-aop + ${spring.boot.version} + org.springframework.boot spring-boot-starter-webflux