Commit 57128434 authored by 郭燕飞's avatar 郭燕飞 💬

Initial commit

parents
sonarqube_feature_preview:
script:
- git config --global user.email "sonar@duiba"
- git config --global user.name "sonar"
- gradle clean
- export
- gradle sonarqube -Dsonar.host.url=http://sonar.dui88.com -Dsonar.branch=dummy -Dsonar.login=reporter -Dsonar.password=duiba123456 -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -x test
stage: test
only:
- /^feature.*$/
tags:
- test
sonarqube_hotfix_preview:
script:
- git config --global user.email "sonar@duiba"
- git config --global user.name "sonar"
- gradle clean
- export
- gradle sonarqube -Dsonar.host.url=http://sonar.dui88.com -Dsonar.branch=dummy -Dsonar.login=reporter -Dsonar.password=duiba123456 -Dsonar.analysis.mode=preview -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -x test
stage: test
only:
- /^(hotfix|release).*$/
tags:
- test
sonarqube_develop_preview:
script:
- git config --global user.email "sonar@duiba"
- git config --global user.name "sonar"
- git checkout origin/develop
- gradle clean
- gradle sonarqube -Dsonar.host.url=http://sonar.dui88.com -Dsonar.login=reporter -Dsonar.password=duiba123456 -x test
only:
- develop
tags:
- test
# readme
buildscript {
ext["springBootVersion"] = "2.2.7.RELEASE"
ext["springCloudVersion"] = "Hoxton.SR6"
ext["guava.version"] = "28.2-jre"
repositories {
maven { url "http://nexus.dui88.com:8081/nexus/content/groups/public/" }
maven { url "https://plugins.gradle.org/m2/" } //sonarqube
maven { url "http://repo.spring.io/plugins-release" }
mavenCentral()
mavenLocal()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.5.RELEASE"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "org.springframework.build.gradle:propdeps-plugin:0.0.7"
}
}
apply plugin: "maven"
apply plugin: "java"
apply plugin: "idea"
apply plugin: "eclipse"
apply plugin: "jacoco"
apply plugin: "io.spring.dependency-management"
apply plugin: "org.springframework.boot"
apply plugin: "propdeps"
test {
ignoreFailures = true
}
group = "cn.com.duiba"
version = "0.0.1-SNAPSHOT"
sourceCompatibility = 1.8
targetCompatibility = 1.8
bootJar {
archiveName = "spring-test-web.jar"
}
configurations {
all*.exclude group: "log4j", module: "log4j"
all*.exclude group: "org.slf4j", module: "slf4j-log4j12"
all*.exclude group: "javax.servlet", module: "servlet-api" //servlet 2.5
all*.exclude group: "com.fasterxml.jackson.dataformat", module: "jackson-dataformat-xml"
}
repositories {
maven { url "http://nexus.dui88.com:8081/nexus/content/groups/public/" }
maven { url "https://plugins.gradle.org/m2/" } //sonarqube
maven { url "http://repo.spring.io/plugins-release" }
mavenCentral()
mavenLocal()
}
dependencyManagement {
dependencies {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-freemarker"
compile "org.springframework.cloud:spring-cloud-starter-config"
compile "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
compile "org.springframework.cloud:spring-cloud-starter-netflix-hystrix"
compile "org.springframework.cloud:spring-cloud-starter-netflix-ribbon"
compile "org.springframework.cloud:spring-cloud-starter-openfeign"
compileOnly "org.projectlombok:lombok"
annotationProcessor "org.projectlombok:lombok"
testCompileOnly "org.projectlombok:lombok"
testAnnotationProcessor "org.projectlombok:lombok"
testCompile "org.springframework.boot:spring-boot-starter-test"
}
install {
enabled = false
}
uploadArchives {
enabled = false
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
uploadArchives {
repositories {
mavenDeployer {
snapshotRepository(url: "http://nexus.dui88.com:8081/nexus/content/repositories/snapshots/") {
authentication(userName: "admin", password: "admin123")
}
repository(url: "http://nexus.dui88.com:8081/nexus/content/repositories/releases/") {
authentication(userName: "admin", password: "admin123")
}
pom.project {
name project.name
packaging "jar"
description project.name
url "www.duiba.com.cn"
scm {
url ""
connection ""
developerConnection ""
}
licenses {
license {
name "No License"
url "http://www.duiba.com.cn"
distribution "repo"
}
}
developers {
developer {
id "xuhengfei"
name "Hengfei Xu"
}
}
}
}
}
}
rootProject.name = "spring-test-web"
package cn.com.duiba.spring.test.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication sa = new SpringApplication(Application.class);
sa.run(args);
}
}
package cn.com.duiba.spring.test.web.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* Created by gyf .
* 2020/10/16 .
*/
@Configuration
@Import(TestAopFactoryBeanImportBeanDefinitionRegistrar.class)
public class TestAopBeanConfig {
// @RefreshScope
// @Bean
// public TestAopBean testAopBean() {
// return new TestAopBean();
// }
// @Bean
// public static TestAopBeanPostProcessor testAopBeanPostProcessor(){
// return new TestAopBeanPostProcessor();
// }
}
package cn.com.duiba.spring.test.web.config;
import cn.com.duiba.spring.test.web.service.TestAopBean;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
/**
* Created by gyf .
* 2020/10/16 .
*/
public class TestAopBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean.getClass() == TestAopBean.class) {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean);
factory.addAdvice(new TestAopBeanMethodInterceptor());
Object proxy = factory.getProxy();
return proxy;
}
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
private static class TestAopBeanMethodInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
String methodName = invocation.getMethod().getName();
System.out.println("我进来过," + methodName);
return invocation.proceed();
}
}
}
package cn.com.duiba.spring.test.web.config;
import cn.com.duiba.spring.test.web.service.TestAopBean;
import javax.annotation.PostConstruct;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
/**
* Created by gyf .
* 2020/10/27 .
*/
public class TestAopFactoryBean implements FactoryBean<TestAopBean>, InitializingBean, DisposableBean {
private TestAopBean testAopBean;
@PostConstruct
public void init() {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(new TestAopBean());
factory.addAdvice(new TestAopBeanMethodInterceptor());
testAopBean = (TestAopBean) factory.getProxy();
}
private static class TestAopBeanMethodInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
String methodName = invocation.getMethod().getName();
System.out.println("我进来过," + methodName);
return invocation.proceed();
}
}
@Override
public TestAopBean getObject() throws Exception {
return testAopBean;
}
@Override
public Class<?> getObjectType() {
return TestAopBean.class;
}
@Override
public void destroy() throws Exception {
testAopBean.destroy();
}
@Override
public void afterPropertiesSet() throws Exception {
testAopBean.afterPropertiesSet();
}
}
package cn.com.duiba.spring.test.web.config;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
/**
* Created by gyf .
* 2020/10/27 .
*/
public class TestAopFactoryBeanImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
String beanId = "testAopFactoryBean";
if(registry.containsBeanDefinition(beanId)){
//已经被TestAopFactoryBeanImportBeanDefinitionRegistrar注册过,跳过
return;
}
BeanDefinition beanDefinition = BeanDefinitionBuilder
.genericBeanDefinition(TestAopFactoryBean.class)
.setScope(RefreshAutoConfiguration.REFRESH_SCOPE_NAME)
.getBeanDefinition();
BeanDefinitionHolder beanDefinitionHolder = new BeanDefinitionHolder(beanDefinition, beanId);
beanDefinitionHolder = ScopedProxyUtils.createScopedProxy(beanDefinitionHolder, registry, true);
BeanDefinitionReaderUtils.registerBeanDefinition(beanDefinitionHolder, registry);
}
}
package cn.com.duiba.spring.test.web.controller;
import cn.com.duiba.spring.test.web.service.TestAopBean;
import javax.annotation.Resource;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by gyf .
* 2020/10/16 .
*/
@RestController
@RequestMapping("/test/aop/bean")
public class TestAopBeanController {
@Resource
private TestAopBean testAopBean;
@SneakyThrows
@GetMapping("/test")
public String test() {
testAopBean.destroy();
testAopBean.afterPropertiesSet();
return testAopBean.test();
}
}
package cn.com.duiba.spring.test.web.service;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
/**
* Created by gyf .
* 2020/10/16 .
*/
public class TestAopBean implements InitializingBean, DisposableBean {
@Override
public void destroy() throws Exception {
// System.out.println("我被销毁了" + ExceptionUtils.getStackTrace(new Exception()));
System.out.println("我被销毁了");
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("我初始化完成了");
}
public String test() {
return "ok";
}
}
# tomcat
server.port=1112
server.tomcat.access-log-enabled=false
server.tomcat.uri-encoding=UTF-8
# logging
logging.file.path=${user.home}/logs/spring-test-web
# \u5F00\u542F\u66B4\u9732\u6240\u6709endpoint
management.endpoints.web.exposure.include=*
spring.application.name=spring-test-web
spring.cloud.config.uri=http://configserver.dui88.com
spring.cloud.config.fail-fast=true
spring.profiles.active=dev
spring.devtools.restart.enabled=false
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="logback/default.xml" />
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<included>
<property name="logpath" value="${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}"/>
<property name="logPattern" value="%d{HH:mm:ss.SSS} %-5level [%thread] %logger{32}[%file:%line] -&gt; %msg%n"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${logPattern}</pattern>
<charset class="java.nio.charset.Charset">utf8</charset>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${logpath}/application.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logpath}/application_%d{yyyy-MM-dd}.log</FileNamePattern>
<maxHistory>10</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${logPattern}</pattern>
</encoder>
</appender>
<!-- 需要记录日志的包 -->
<logger name="cn.com.duiba" level="INFO"/>
<logger name="cn.com.duiba" level="INFO"/>
<root level="WARN">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</included>
package cn.com.duiba.spring.test.web;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = Application.class)
@AutoConfigureMockMvc
public abstract class BaseTest {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment