Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-test-web
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
郭燕飞
spring-test-web
Commits
57128434
Commit
57128434
authored
Oct 27, 2020
by
郭燕飞
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
476 additions
and
0 deletions
+476
-0
.gitlab-ci.yml
.gitlab-ci.yml
+37
-0
README.md
README.md
+1
-0
build.gradle
build.gradle
+140
-0
settings.gradle
settings.gradle
+1
-0
Application.java
src/main/java/cn/com/duiba/spring/test/web/Application.java
+14
-0
TestAopBeanConfig.java
...n/com/duiba/spring/test/web/config/TestAopBeanConfig.java
+25
-0
TestAopBeanPostProcessor.java
...uiba/spring/test/web/config/TestAopBeanPostProcessor.java
+42
-0
TestAopFactoryBean.java
.../com/duiba/spring/test/web/config/TestAopFactoryBean.java
+57
-0
TestAopFactoryBeanImportBeanDefinitionRegistrar.java
...nfig/TestAopFactoryBeanImportBeanDefinitionRegistrar.java
+34
-0
TestAopBeanController.java
...iba/spring/test/web/controller/TestAopBeanController.java
+28
-0
TestAopBean.java
...ava/cn/com/duiba/spring/test/web/service/TestAopBean.java
+26
-0
application.properties
src/main/resources/application.properties
+10
-0
bootstrap.properties
src/main/resources/bootstrap.properties
+6
-0
logback.xml
src/main/resources/logback.xml
+6
-0
default.xml
src/main/resources/logback/default.xml
+34
-0
BaseTest.java
src/test/java/cn/com/duiba/spring/test/web/BaseTest.java
+15
-0
No files found.
.gitlab-ci.yml
0 → 100644
View file @
57128434
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.md
0 → 100644
View file @
57128434
# readme
build.gradle
0 → 100644
View file @
57128434
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"
}
}
}
}
}
}
settings.gradle
0 → 100644
View file @
57128434
rootProject
.
name
=
"spring-test-web"
src/main/java/cn/com/duiba/spring/test/web/Application.java
0 → 100644
View file @
57128434
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
);
}
}
src/main/java/cn/com/duiba/spring/test/web/config/TestAopBeanConfig.java
0 → 100644
View file @
57128434
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();
// }
}
src/main/java/cn/com/duiba/spring/test/web/config/TestAopBeanPostProcessor.java
0 → 100644
View file @
57128434
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
();
}
}
}
src/main/java/cn/com/duiba/spring/test/web/config/TestAopFactoryBean.java
0 → 100644
View file @
57128434
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
();
}
}
src/main/java/cn/com/duiba/spring/test/web/config/TestAopFactoryBeanImportBeanDefinitionRegistrar.java
0 → 100644
View file @
57128434
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
);
}
}
src/main/java/cn/com/duiba/spring/test/web/controller/TestAopBeanController.java
0 → 100644
View file @
57128434
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
();
}
}
src/main/java/cn/com/duiba/spring/test/web/service/TestAopBean.java
0 → 100644
View file @
57128434
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"
;
}
}
src/main/resources/application.properties
0 → 100644
View file @
57128434
# 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
=
*
src/main/resources/bootstrap.properties
0 → 100644
View file @
57128434
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
src/main/resources/logback.xml
0 → 100644
View file @
57128434
<?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
src/main/resources/logback/default.xml
0 → 100644
View file @
57128434
<?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] -> %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>
src/test/java/cn/com/duiba/spring/test/web/BaseTest.java
0 → 100644
View file @
57128434
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
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment