문제

Update 5: 최신 Eclipse를 기반으로 최신 Spring Toolssuite IDE를 다운로드했습니다. 프로젝트를 Maven 프로젝트로 가져 오면 Eclipse/STS는 Maven 목표를 사용하여 프로젝트를 구축하는 것으로 보입니다. 이는 SASPERJ가 마침내 일식에서 올바르게 작동 함을 의미합니다.

Update 4: Eclipse의 메커니즘을 효과적으로 우회하여 컴파일 타임 직조를 위해 Maven + AnalpegJ 플러그인을 사용했습니다.

3 : 업데이트 3. SageJ의 Eclipse 플러그인은 Eclipse가 Tomcat에 올바르게 게시하는 능력을 깨뜨리는 것 같습니다. 프로젝트에서 AspectJ 기능을 제거하면 다시 올바르게 게시 할 수 있습니다. 매우 성가신.

Update 2: 나는 지금 이클립스에서 일하고 있습니다. 이것을 말하는 것은 매우 불편하지만, 나는 Eclipse 또는 Maven Builds에서 어떻게 작동했는지 전혀 모른다. 런타임 문제가 아닌 컴파일 문제 인 것 같습니다.

Update 1: Maven Builds를 통해 작동하기 위해 이것을 얻은 것 같습니다. 그러나 나는 방법을 모릅니다. Eclipse는 여전히 작동하지 않습니다. 내가 변경 한 유일한 것 pom.xml 이 (무의미한?) 구성 매개 변수를 추가 했습니까?

<source>1.6</source>
<complianceLevel>1.6</complianceLevel>
<verbose>true</verbose>
<showWeaveInfo>true</showWeaveInfo>
<outxml>true</outxml>

나는 실제로 반복되는 것이 걱정된다 이 문제, 모든 것이 일관되지 않은 곳. 더 많이 배우 면서이 질문을 계속 업데이트하겠습니다.

일식과 관련하여, 나는 직조하고 싶은 이진 측면을 취함으로써 약간의 진전을 이루었습니다. Spring-Aspect.jar - 내 클래스 경로에서 복사합니다. 그런 다음 지금 이것을 외부 항아리에 추가합니다 측면 경로. 이 작업을 수행 한 후 Eclipse는 내 코드에서 Sagej 마커를 제대로 보여줍니다. 내가 떠날 수 없다는 것이 짜증나고 있습니다 Spring-Aspect.jar자바 빌드 경로 Maven 플러그인을 통해 Maven이 관리합니다. 그러나 어떤 이유로 든 AnspectJ 플러그인은 이진 측면이 측면 경로.


원본 게시물 : @Configurable은 스프링 주석으로, 종속성을 스프링 외부 (예 : 최대 절전 모드 또는 일부 공장 클래스)에 인스턴스화하는 물체에 주입 할 수 있습니다.

나는 이전에로드 타임 직조와 함께이 주석을 사용하고있었습니다. 주로 일했다. 때때로 나는 부팅 할 것이고 아무것도 주입하지 않을 것입니다. 이 문제는 생성되었습니다 이 stackoverflow 질문. 답이 많지 않았지만 대부분 신뢰성이 높아서 컴파일 타임 직조를 시도한다고 제안했습니다.

Eclipse 및 Maven 용 Ansporj 플러그인을 설치했습니다. 이 두 가지 모두 올바르게 편집 된 클래스로 보이는 것을 생산합니다. AspectJ Compilation 전에 텍스트 편집기에서 클래스 중 하나를 열었으며 SuciorJ에 대한 참조를 찾지 못했습니다. AspectJ 컴파일 후에 열었고 Eclipse와 Maven 생성 버전 모두를 참조합니다. org.aspectj.weaver.methoddeclarationlineNumber. 이것이 제가 올바르게 컴파일되고 있다고 가정합니다. 문제는 일단 배포되면 종속성이 주입되지 않는다는 것입니다.

내 봄 ApplicationContext.xml 다음을 포함합니다.

    <context:spring-configured />

    <context:component-scan base-package="com.myapp" />

@configurable으로 표시된 클래스에 필요한 것이 무엇입니까? 로드 타임 직조에서 컴파일 타임 직조로 변환하는 동안 제거했습니다. 메타 -inf/aop.xml, u003Ccontext:load-time-weaver />ApplicationContext.xml, 그리고 내 봄의 Tomcat 위버 context.xml.

이 문제를 어떻게 더 조사 할 수 있습니까? 가능한 원인은 무엇입니까?

도움이 되었습니까?

해결책

Compile Time 직조를 사용하여 Maven에서 우리에게 작동합니다. 다음 플러그인을 추가하십시오.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
    <compilerVersion>1.6</compilerVersion>
    <fork>true</fork>
    <source>1.6</source>
    <target>1.6</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
    <execution>
        <id>compile</id>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
            <verbose>false</verbose>
            <outxml>true</outxml>
            <aspectLibraries>
                <aspectLibrary>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
            </aspectLibraries>
        </configuration>
        <goals>
            <goal>compile</goal>
        </goals>
    </execution>
    <execution>
        <id>test-compile</id>
        <configuration>
            <source>1.6</source>
            <target>1.6</target>
            <verbose>false</verbose>
            <aspectLibraries>
                <aspectLibrary>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aspects</artifactId>
                </aspectLibrary>
            </aspectLibraries>
        </configuration>
        <goals>
            <goal>test-compile</goal>
        </goals>
    </execution>
</executions>
<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.6.4</version>
    </dependency>
</dependencies>
</plugin>

단위 테스트 및 컴파일을 위해 다른 측면 라이브러리를 추가 할 수 있도록 두 개의 개별 실행 단계로 수행됩니다.

또한 스프링 아시후 라이브러리에 다음의 종속성이 추가됩니다.

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <scope>compile</scope>
    </dependency>

다른 팁

이것이 당신을위한 대안이라면 내 앱에서로드 타임 직조를 성공적으로 구성했습니다.

내 환경 :

  • JDK-1.6
  • Spring-2.5.6
  • eclipselink-1.1.0이있는 JPA

구성 세부 사항 :

스프링 XML 구성 :

<context:annotation-config/>
<context:spring-configured/>
<context:load-time-weaver/>

<bean id="baseEntity" class="package.name.BaseEntity" scope="prototype">
  <property name="historyHandler" ref="historyHandler" />
</bean>

<bean id="historyHandler" class="package.name.HistoryJpaHandler" scope="prototype">
  <property name="historyDao" ref="historyDao" />
</bean>

<bean id="historyDao" class="package.name.HistoryJpaDao">
  <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

봄 주석

@Configurable("baseEntity")
public abstract class BaseEntity

@Configurable("historyHandler")
public class HistoryJpaHandler extends SessionEventAdapter implements HistoryHandler 

Java VM 매개 변수

<JAVA_HOME>/bin/java -javaagent:/full/path/to/spring-agent-2.5.6.jar

HistoryHandler 및 BaseEntitty 인스턴스는 Ecliselink에 의해 만들어집니다. HistoryEntitty의 HistoryHandler 및 HistoryHandler의 HistoryDao는로드 타이어링에 의해 설정됩니다.

Eclipse Run 구성 또는 Tomcats Catalina.sh/bat에서 VM 매개 변수를 설정할 수 있습니다.

이 주석에 대해 스프링을 올바르게 구성하지 않으면 @Configurable 클래스의 분야를 만들면 NullPointerException이 발생합니다. 다음 단계에 따라 @Configurable 주석이 올바르게 작동하도록하십시오

이 방법을 호출합니다 Spring-Beans를 비 스프링 메이드 클래스에 주입하기위한 시간 제작 시간 빌드 시간.

첫 번째 단계는이 플러그인을 Eclipse에 설치하는 것입니다.

이 두 업데이트 사이트에서 Eclipse가 제안한 내용을 설치합니다.

http://download.eclipse.org/tools/ajdt/43/update
http://dist.springsource.org/release/AJDT/configurator/ 

설치 후 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 수행하십시오.

Configure > Convert to Aspectj
Maven > Update

다음으로 pom.xml에 이것들을 추가해야합니다.

종속성에 따라 추가 :

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>

플러그인 추가 : 추가 :

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.5</version>
            <configuration>
                <showWeaveInfo>true</showWeaveInfo>
                <source>1.7</source>
                <target>1.7</target>
                <Xlint>ignore</Xlint>
                <complianceLevel>1.7</complianceLevel>
                <encoding>UTF-8</encoding>
                <verbose>false</verbose>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>1.7.0</version>
                </dependency>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>1.7.0</version>
                </dependency>
            </dependencies>
        </plugin>

중요한: 사용하지 마십시오 <pluginManagment> 아래로 태그 <build> 꼬리표. pom.xml은 다음과 같은 것이어야합니다.

<project ....>
    ....
    <dependencies>
        <dependency> 
                    ....
        </dependency>
                ....
    </dependencies>
    <build>
        <plugins>
            <plugin>
                            ....
            </plugin>
                        ....
        </plugins>
    </build>
</project>

마지막으로 추가 <context:spring-configured /> 스프링 응용 프로그램 컨텍스트 구성 파일에.

이제 Pojo 클래스에 주석을 달 수 있습니다 @Configurable 그리고 스프링 콩을 사용하여 주입합니다 @Autowired 주석. 이 방법으로 해당 POJO의 새 인스턴스를 만들 때마다 자동으로 구성됩니다 (예 : 종속성이 주입 됨).

Eclipse ClassPath 문제에 관한 한,이 문제가 유용 할 수 있습니다.

그만큼 m2eclipse 플러그인 선택 사항이 있습니다 AJDT 통합. 통합은 Species-Maven-Plugin의 구성의 AspectLibraries 섹션을 읽고 항아리를 Eclipse의 Spect Path에 기여합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top