Cas*_*sey 3 spring spring-aop gradle load-time-weaving spring-boot
我的目标是获得一个简单的facej + spring aop设置,这样我就可以在一个类上使用@Configurable.另一个限制是它需要使用加载时编织,因为Lombok不能与CTW一起使用.
好消息:我有它的工作!
坏消息:控制台充斥着[Xlint:cantFindType]错误.见下面的结果部分.
我有一个单独的类注释@Configurable.它是杰克逊使用和实例化的一个类,因此需要AOP.它不是很有趣所以我不会在这里展示它.它只是一个普通的类,带有Configurable的单个注释,@Autowired里面有一个bean.
我的Application类具有通常的注释:
@SpringBootApplication
@EnableSpringConfigured
@EnableLoadTimeWeaving
public class MyApplication {
Run Code Online (Sandbox Code Playgroud)
我的build.gradle有所有常见的嫌疑人.样品:
configurations {
springinstrument
}
dependencies {
compile('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-aop')
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.plugin:spring-plugin:1.2.0.RELEASE')
..snip..
runtime('org.springframework:spring-instrument:4.+')
springinstrument "org.springframework:spring-instrument:4.+"
runtime configurations.springinstrument.dependencies
}
test.doFirst {
jvmArgs "-javaagent:${configurations.springinstrument.asPath}"
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下args运行JUnit测试(通过Intellij的运行配置)
-ea
-javaagent:/Users/me/.gradle/caches/modules-2/files-2.1/org.springframework/spring-instrument/4.3.3.RELEASE/5db399fa5546172b9c107817b4abaae6b379bb8c/spring-instrument-4.3.3.RELEASE.jar
Run Code Online (Sandbox Code Playgroud)
我有一个src/main/resources/META-INF/aop.xml包含:
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
<aspectj>
<weaver options="-Xreweavable -showWeaveInfo">
<!-- only weave classes with @Configurable interface -->
<include within="@org.springframework.beans.factory.annotation.Configurable */>
</weaver>
</aspectj>
Run Code Online (Sandbox Code Playgroud)
但是,我怀疑这个文件没有被提取.我放在文件中的内容并不重要,结果总是一样的.即使我把随机无效的XML.
junit测试是一个简单的Jackson序列化 - 反序列化测试,使用带@Configurable注释的类.
测试类有注释:
@SpringBootTest
@RunWith(SpringRunner.class)
Run Code Online (Sandbox Code Playgroud)
LTW是实际工作的,我的测试在通过Intellij运行时通过上面的jvm args.
但是,应用程序的启动时间明显更长,并且日志充满了Xlint:cantFindType错误
例:
2016-11-07 19:28:21.944 INFO 45213 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
[AppClassLoader@18b4aac2] error can't determine implemented interfaces of missing type org.springframework.security.ldap.authentication.LdapAuthenticationProvider
when weaving type org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer
when weaving classes
when weaving
[Xlint:cantFindType]
[AppClassLoader@18b4aac2] error can't determine implemented interfaces of missing type io.undertow.server.handlers.accesslog.AccessLogHandler
when weaving type org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
when weaving classes
when weaving
[Xlint:cantFindType]
[AppClassLoader@18b4aac2] error can't determine implemented interfaces of missing type io.undertow.server.handlers.accesslog.AccessLogHandler
when weaving type org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
when weaving classes
when weaving
[Xlint:cantFindType]
[AppClassLoader@18b4aac2] error can't determine implemented interfaces of missing type io.undertow.server.handlers.accesslog.AccessLogHandler
when weaving type org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
when weaving classes
when weaving
[Xlint:cantFindType]
.. many more.. all in the org.springframework.boot package
Run Code Online (Sandbox Code Playgroud)
当我运行测试时gradle test --tests *MyTestClass,测试因为NullPointerException而失败..猜猜是什么,@Autowired我期望自动注入的bean.
我得到它与gradle测试配置,huzzah!我已经更新了上面的配置.但是..它在我的IDE中运行它遇到了同样的问题:the Xlint:cantFindType
所以问题:
gradle配置错误,因此通过gradle运行应用程序失败.如何修复gradle配置?
该Xlint:cantFindType错误.是不是拿起了aop.xml?怎么解决这个?
我还没有找到一个使用aop.xml的简单的spring-boot + gradle + @Configurable示例
我解决了这个问题,而且相当尴尬.
aop.xml没有被捡起来.META_INF/类路径上的目录中,而不是META-INF/.这是一个非常重要的区别.无论如何,我已经使用最小配置来更新问题,以便@Configurable使用现代spring-boot和gradle设置以及Lombok支持的加载时间编织.希望它对某人有用.
| 归档时间: |
|
| 查看次数: |
2091 次 |
| 最近记录: |