- Krieg 1: Demo < /li>
Krieg 2: Interceptor < /li>
MyController.java
Code: Select all
package com.fredan.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fredan.demo.dto.StatusDto;
import com.fredan.demo.service.MyService;
@RestController
public class MyController {
@Autowired
private MyService myService;
@GetMapping("/counter")
public ResponseEntity executeCounter() {
myService.executeCounter();
StatusDto dto = new StatusDto();
dto.setStatus("success");
return ResponseEntity.ok(dto);
}
}
Code: Select all
package com.fredan.demo.service.impl;
import org.springframework.stereotype.Service;
import com.fredan.demo.service.MyService;
import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class MyServiceImpl implements MyService {
@Override
public void executeCounter() {
log.info("=============================== inside MyServiceImpl.executeCounter - Start =============================");
for (int counter = 1; counter
[b] Interceptor App < /strong> < /p>
application.java < /strong> < /p>
package com.fredan.interceptor;
import java.lang.instrument.Instrumentation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.instrument.InstrumentationSavingAgent;
import net.bytebuddy.agent.ByteBuddyAgent;
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
Instrumentation instrumentation = ByteBuddyAgent.install();
InstrumentationSavingAgent.premain("", instrumentation);
SpringApplication.run(Application.class, args);
}
}
Code: Select all
package com.fredan.interceptor.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import lombok.extern.slf4j.Slf4j;
@Aspect
@Slf4j
public class MyServiceAspect {
@Pointcut("execution(public void com.fredan.demo.service.impl.MyServiceImpl.executeCounter())")
public void executeCounterPointcut() {
// this is a method that defines a pointcut of an aspect
}
@Before("executeCounterPointcut()")
public void beforeMethod(JoinPoint jp) {
log.info("Executing MyServiceAspect.beforeMethod() BEFORE calling " + jp.getSignature().getDeclaringTypeName() + "." + jp.getSignature().getName());
}
@After("executeCounterPointcut()")
public void afterMethod(JoinPoint jp) {
log.info("Executing MyServiceAspect.afterMethod() AFTER calling " + jp.getSignature().getDeclaringTypeName() + "." + jp.getSignature().getName());
}
}
Code: Select all
package com.fredan.interceptor.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableLoadTimeWeaving;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
@Configuration
@EnableSpringConfigured
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)
public class AopConfig {
}
Code: Select all
Code: Select all
4.0.0
com.fredan.interceptor
interceptor-parent
${revision}
interceptor
war
Interceptor WAR
com.fredan.demo
demo
classes
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-log4j2
org.springframework
spring-aspects
org.springframework
spring-instrument
org.projectlombok
lombok
provided
org.aspectj
aspectjrt
org.aspectj
aspectjweaver
net.bytebuddy
byte-buddy-agent
${project.artifactId}
org.springframework.boot
spring-boot-maven-plugin
verfolgt habe
Das Problem ist im Moment, dass keine Aspekte gewebt sind, da ich nicht " Debugve Waving < /strong>" auf dem Protokoll sehe. Einige Zeilen im Log unten sind für die Kürze weggelassen.
Code: Select all
2025-02-01 16:17:41 [ INFO] my-interceptor - DefaultContextLoadTimeWeaver:82 - Found Spring's JVM agent for instrumentation
[AppClassLoader@764c12b6] info AspectJ Weaver Version 1.9.22.1 built on Friday May 10, 2 0 2 4 a t 2 3 : 2 3 : 1 6 P D T < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o r e g i s t e r c l a s s l o a d e r s u n . m i s c . L a u n c h e r $ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o u s i n g c o n f i g u r a t i o n / C : / p r o j e c t s / i n t e r c e p t o r - p a r e n t / i n t e r c e p t o r / t a r g e t / c l a s s e s / M E T A - I N F / a o p . x m l < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o u s i n g c o n f i g u r a t i o n f i l e : / C : / U s e r s / l a n g f r e d / . m 2 / r e p o s i t o r y / o r g / s p r i n g f r a m e w o r k / s p r i n g - a s p e c t s / 4 . 3 . 2 5 . R E L E A S E / s p r i n g - a s p e c t s - 4 . 3 . 2 5 . R E L E A S E . j a r ! / M E T A - I N F / a o p . x m l < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o r e g i s t e r a s p e c t c o m . f r e d a n . i n t e r c e p t o r . a s p e c t . M y S e r v i c e A s p e c t < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o r e g i s t e r a s p e c t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . a s p e c t j . A n n o t a t i o n B e a n C o n f i g u r e r A s p e c t < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o r e g i s t e r a s p e c t o r g . s p r i n g f r a m e w o r k . s c h e d u l i n g . a s p e c t j . A n n o t a t i o n A s y n c E x e c u t i o n A s p e c t < b r / > [ A p p C l a s s L o a d e r @ 7 6 4 c 1 2 b 6 ] i n f o r e g i s t e r a s p e c t o r g . s p r i n g f r a m e w o r k . t r a n s a c t i o n . a s p e c t j . A n n o t a t i o n T r a n s a c t i o n A s p e c t < b r / > [ A ppClassLoader@764c12b6] error can't determine superclass of missing type org.springframework.transaction.interceptor.TransactionAspectSupport
[Xlint:cantFindType]
[AppClassLoader@764c12b6] info register aspect org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect
[AppClassLoader@764c12b6] info deactivating aspect 'org.springframework.transaction.aspectj.JtaAnnotationTransactionAspect' as it requires type 'javax.transaction.Transactional' which cannot be found on the classpath
[AppClassLoader@764c12b6] info register aspect org.springframework.cache.aspectj.AnnotationCacheAspect
[AppClassLoader@764c12b6] info register aspect org.springframework.cache.aspectj.JCacheCacheAspect
[AppClassLoader@764c12b6] info deactivating aspect 'org.springframework.cache.aspectj.JCacheCacheAspect' as it requires type 'org.springframework.cache.jcache.interceptor.JCacheAspectSupport' which cannot be found on the classpath
[AppClassLoader@764c12b6] info deactivating aspect 'org.springframework.cache.aspectj.JCacheCacheAspect' as it requires type 'javax.cache.annotation.CacheResult' which cannot be found on the classpath
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$$FastClassBySpringCGLIB$$a7cec5b4'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration$$EnhancerBySpringCGLIB$$1dfdd984$$FastClassBySpringCGLIB$$be80dce7'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$FastClassBySpringCGLIB$$28b34ea5'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$62e6f395$$FastClassBySpringCGLIB$$367044a'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$$FastClassBySpringCGLIB$$ee97f15b'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$$EnhancerBySpringCGLIB$$92a5cf0b$$FastClassBySpringCGLIB$$49757e60'
[AppClassLoader@764c12b6] debug not weaving 'com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver'
[AppClassLoader@764c12b6] debug not weaving 'com.fasterxml.jackson.core.Version'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement'
...
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.beans.ExtendedBeanInfo$PropertyDescriptorComparator'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.beans.PropertyDescriptorUtils'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.beans.ExtendedBeanInfo$1'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.jackson.JsonComponent'
[AppClassLoader@764c12b6] debug not weaving 'com.fasterxml.jackson.databind.ser.FilterProvider'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$FastClassBySpringCGLIB$$596316ac'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$b09a317c$$FastClassBySpringCGLIB$$89c759cd'
...
[AppClassLoader@764c12b6] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
[AppClassLoader@764c12b6] debug cannot weave 'javax.validation.ConstraintViolation'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.NonRecursivePropertyPlaceholderHelper'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration$$FastClassBySpringCGLIB$$7b26c9e9'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration$$EnhancerBySpringCGLIB$$9b4e2359$$FastClassBySpringCGLIB$$5caedacf'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.context.support.MessageSourceAccessor'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.http.ResponseEntity'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.http.HttpEntity'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.bind.annotation.ResponseBody'
[AppClassLoader@764c12b6] debug not weaving 'com.sun.proxy.$Proxy75'
...
2025-02-01 16:17:41 [ INFO] my-interceptor - RequestMappingHandlerAdapter:557 - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6236eb5f: startup date [Sat Feb 01 16:17:40 SGT 2025]; root of context hierarchy
...
[AppClassLoader@764c12b6] debug not weaving 'com.sun.proxy.$Proxy77'
...
2025-02-01 16:17:42 [ INFO] my-interceptor - RequestMappingHandlerMapping:544 - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistration'
2025-02-01 16:17:42 [ INFO] my-interceptor - RequestMappingHandlerMapping:544 - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.resource.ResourceTransformerChain'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.resource.PathResourceResolver'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.resource.AbstractResourceResolver'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.resource.ResourceResolver'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.http.converter.ResourceRegionHttpMessageConverter'
2025-02-01 16:17:42 [ INFO] my-interceptor - SimpleUrlHandlerMapping:364 - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2025-02-01 16:17:42 [ INFO] my-interceptor - SimpleUrlHandlerMapping:364 - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.util.UriComponentsBuilder'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.handler.HandlerExceptionResolverComposite'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.config.annotation.UrlBasedViewResolverRegistration'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.config.annotation.ViewResolverRegistry$GroovyMarkupRegistration'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.config.annotation.ViewResolverRegistry$FreeMarkerRegistration'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.config.annotation.ViewResolverRegistry$ScriptRegistration'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.config.annotation.ViewResolverRegistry$TilesRegistration'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.config.annotation.ViewResolverRegistry$VelocityRegistration'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.view.ViewResolverComposite'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration$$FastClassBySpringCGLIB$$6a2f79af'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration$$EnhancerBySpringCGLIB$$8d23dddf$$FastClassBySpringCGLIB$$68223559'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.servlet.resource.ResourceTransformer'
2025-02-01 16:17:42 [ INFO] my-interceptor - SimpleUrlHandlerMapping:364 - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
...
[AppClassLoader@764c12b6] debug not weaving 'com.sun.proxy.$Proxy78'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.multipart.MultipartHttpServletRequest'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.multipart.MultipartRequest'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.web.client.RestTemplateCustomizer'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration$RestTemplateConfiguration$$FastClassBySpringCGLIB$$a7c76372'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration$RestTemplateConfiguration$$EnhancerBySpringCGLIB$$5c362902$$FastClassBySpringCGLIB$$875bcac1'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.http.client.ClientHttpRequestFactory'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.client.ResponseErrorHandler'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.http.client.ClientHttpRequestInterceptor'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.web.util.UriTemplateHandler'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.http.client.support.BasicAuthorizationInterceptor'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.aop.scope.ScopedObject'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.aop.RawTargetAccess'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.context.event.EventListenerMethodProcessor$1'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.context.event.EventListener'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.logging.LoggerConfiguration'
2025-02-01 16:17:42 [ INFO] my-interceptor - AnnotationMBeanExporter:431 - Registering beans for JMX exposure on startup
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.jmx.export.MBeanExporter$2'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.jmx.export.MBeanExporter$1'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.jmx.export.annotation.ManagedResource'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.context.support.DefaultLifecycleProcessor'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.context.support.LiveBeansView'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.context.support.LiveBeansViewMBean'
2025-02-01 16:17:42 [ INFO] my-interceptor - Http11NioProtocol:180 - Starting ProtocolHandler ["http-nio-8082"]
2025-02-01 16:17:42 [ INFO] my-interceptor - NioSelectorPool:180 - Using a shared selector for servlet write/read
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.net.NioBlockingSelector'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.net.NioBlockingSelector$BlockPoller'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.collections.SynchronizedQueue'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.TaskQueue'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.TaskThreadFactory'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.TaskThread'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.ThreadPoolExecutor'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.StopPooledThreadException'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.ThreadPoolExecutor$RejectHandler'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.TaskThread$WrappingRunnable'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.threads.Constants'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.util.net.AbstractEndpoint$Acceptor$AcceptorState'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.catalina.ContainerServlet'
[AppClassLoader@764c12b6] debug cannot weave 'javax.servlet.annotation.MultipartConfig'
[AppClassLoader@764c12b6] debug cannot weave 'javax.servlet.SingleThreadModel'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.catalina.ContainerEvent'
2025-02-01 16:17:42 [ INFO] my-interceptor - TomcatEmbeddedServletContainer:210 - Tomcat started on port(s): 8082 (http)
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.util.ConcurrentReferenceHashMap$EntrySet'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.util.ConcurrentReferenceHashMap$EntryIterator'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.ApplicationRunner'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.boot.CommandLineRunner'
[AppClassLoader@764c12b6] debug not weaving 'org.springframework.util.StopWatch$TaskInfo'
2025-02-01 16:17:42 [ INFO] my-interceptor - Application:57 - Started Application in 1.474 seconds (JVM running for 2.456)
[AppClassLoader@764c12b6] debug not weaving 'org.apache.catalina.webresources.Cache$EvictionOrder'
[AppClassLoader@764c12b6] debug not weaving 'org.apache.tomcat.PeriodicEventListener'