Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I use
@EnableLoadTimeWeaving
with Spring Boot but getting Maven exception when the server boots up
°ERROR§ Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:run (default-cli) on project api-server: Could not exec java: Application finished with exit code: 1 -> °Help 1§
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:run (default-cli) on project api-server: Could not exec java
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
My Spring Boot configuration is as follows
@EnableAsync(proxyTargetClass = true)
@EnableSpringConfigured
@EnableLoadTimeWeaving
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@ComponentScan(
basePackageClasses = {io.skyledge.incontrol.Application.class},
lazyInit = true
and Maven dependencies are as follows
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>5.1.3.RELEASE</version>
</dependency>
–
–
Your main problem is that you should run your application with the AspectJ weaver as a Java agent. If you also add Spring-Instrument as a second Java agent you can avoid adding the weaver to your application class as a bean explicitly, Spring will then take care of it. As you have to modify the command line anyway, just add both agents:
-javaagent:/path/to/spring-instrument-5.0.9.RELEASE.jar -javaagent:/path/to/aspectjweaver-1.8.13.jar
Actually, you also do not need @EnableAspectJAutoProxy (despite the name only used for Spring AOP) because you already use @EnableLoadTimeWeaving (for AspectJ LTW).
In order to avoid an error message about "circular view path" later, you should also add a @ResponseBody annotation to your greeting method:
public @ResponseBody String greeting(...)
I also recomment to add the resource file META-INF/aop.xml in order to avoid lots of error messages due to aspects being applied to all sorts of Spring and 3rd party code and to be able to more exactly tell AspectJ what to weave, what to log etc. With this configuration in your project...
<?xml version="1.0"?>
<!-- AspectJ load-time weaving config file with Spring aspects -->
<aspectj>
<!--<weaver options="-verbose -showWeaveInfo -Xlint:ignore">-->
<weaver options="-showWeaveInfo -Xlint:ignore">
<include within="example..*"/>
</weaver>
<!-- It also works if you omit this section -->
<aspects>
<aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/>
<aspect name="org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect"/>
<aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>
<aspect name="org.springframework.cache.aspectj.AnnotationCacheAspect"/>
</aspects>
</aspectj>
... I am getting this kind of log output:
[AppClassLoader@18b4aac2] warning javax.* types are not being woven because the weaver option '-Xset:weaveJavaxPackages=true' has not been specified
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.5.RELEASE)
2018-12-16 09:54:23.804 INFO 5784 --- [ main] example.Application : Starting Application on Xander-Ultrabook with PID 5784 (C:\Users\alexa\Documents\java-src\SO_AJ_SpringConfigurableBeans\target\classes started by alexa in C:\Users\alexa\Documents\java-src\SO_AJ_SpringConfigurableBeans)
2018-12-16 09:54:23.804 INFO 5784 --- [ main] example.Application : No active profile set, falling back to default profiles: default
2018-12-16 09:54:23.867 INFO 5784 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7c83dc97: startup date [Sun Dec 16 09:54:23 ICT 2018]; root of context hierarchy
2018-12-16 09:54:24.659 INFO 5784 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-12-16 09:54:24.674 INFO 5784 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-12-16 09:54:24.674 INFO 5784 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.34
(...)
2018-12-16 09:54:25.049 INFO 5784 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/greeting],methods=[GET]}" onto public java.lang.String example.GreetingController.greeting(java.lang.String,org.springframework.ui.Model)
(...)
2018-12-16 09:54:25.315 INFO 5784 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-12-16 09:54:25.315 INFO 5784 --- [ main] example.Application : Started Application in 1.848 seconds (JVM running for 3.272)
2018-12-16 10:10:39.050 INFO 5784 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-12-16 10:10:39.051 INFO 5784 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2018-12-16 10:10:39.066 INFO 5784 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 15 ms
[AppClassLoader@18b4aac2] weaveinfo Extending interface set for type 'example.PrintDelegator' (PrintDelegator.java) to include 'org.springframework.beans.factory.aspectj.ConfigurableObject' (AnnotationBeanConfigurerAspect.aj)
[AppClassLoader@18b4aac2] weaveinfo Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'example.PrintDelegator' (PrintDelegator.java:7) advised by before advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractDependencyInjectionAspect.aj:77) [with runtime test]
[AppClassLoader@18b4aac2] weaveinfo Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'example.PrintDelegator' (PrintDelegator.java:7) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractDependencyInjectionAspect.aj:86) [with runtime test]
[AppClassLoader@18b4aac2] weaveinfo Join point 'initialization(void example.PrintDelegator.<init>())' in Type 'example.PrintDelegator' (PrintDelegator.java:7) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractDependencyInjectionAspect.aj:86) [with runtime test]
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.