作为迁移到 Java 8 和纪念 Spring 4 的一部分,我想我会升级到所有 64 位代码。此应用程序在 32 位上完美运行,但加载时间编织在 64 位上不起作用(实际上甚至不加载)。
架构细节:
在 Windows 上的 Spring Tool Suite 3.5.1 下测试。部署目标 RHEL
JVM启动:
-javaagent:C:\Users\...\.m2\repository\org\springframework\spring-instrument\4.0.5.RELEASE\spring-instrument-4.0.5.RELEASE.jar
Run Code Online (Sandbox Code Playgroud)
冒犯的Bean:
@Bean()
public LoadTimeWeaver loadTimeWeaver() {
return new org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver();
}
Run Code Online (Sandbox Code Playgroud)
错误很简单:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'entityManagerFactory' defined in class path resource com/xxxx/config/DataContextConfig.class]:
Invocation of init method failed; nested exception is java.lang.IllegalStateException:
Must start with Java agent to …Run Code Online (Sandbox Code Playgroud) 我的目标是获得一个简单的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 …Run Code Online (Sandbox Code Playgroud) 看看这个Eclipse Bug似乎Java Verifier(自1.6起)与ApsectJ存在问题.
错误说AspectJ 1.8.1将解决问题.但是在Java8u11中使用它仍然会得到验证错误.
我在STS 3.6.0(Eclipse 4.4)下运行JUnit4.我相信这个配置是所有软件包中最新的.
用请求的示例完全替换了剩下的文本.这似乎仅限于@Around建议. @Before工作正常.
JUnit的:
package com.test.aspectjdemo.junit;
import static org.junit.Assert.*;
import org.junit.Test;
import com.test.aspectjdemo.domain.AspectTarget;
public class AspectTargetTest {
@Test
public void testFirstMethod() throws Throwable {
AspectTarget aspectTarget = new AspectTarget();
aspectTarget.firstMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
Vmarg:-javaagent:C:.... m2\repository\org\aspectj\aspectjweaver\1.8.1\aspectjweaver-1.8.1.jar
正在测试的类(我有一些问题,因为显然声明它抛出Throwable,这是有道理的,但这个简单的测试没有抛出任何东西.所以我添加了一个虚假的异常使它编译:
package com.test.aspectjdemo.domain;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class AspectTarget {
final Logger logger = LogManager.getLogger();
int x = 1;
public void firstMethod() throws Throwable {
logger.info("Start First Method");
x = secondMethod(x);
logger.info("Exit X is {}", x); …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我想将纯粹的aspectj与spring-boot结合使用在配置项目时,我们遇到了一些问题.
发现了另一个类似的问题,但这对我们没有帮助.
这就是我们做的:
这是我们在github的回购链接.https://github.com/svenhornberg/MDSD
这是Travis-CI构建日志https://travis-ci.org/svenhornberg/MDSD/builds
但它仍然没有像它应该的那样工作.
我想我需要一些帮助.