更新5: 我已经下载最新的春天ToolsSuite IDE基于最新的食。当我进我的项目作为一个家项目,蚀/STS出现要使用专家的目标,为建设我的项目。这意味着模型或许最终可以正常工作在蚀。

更新4: 我已经结束了只是使用家+样aspect插件的编写时织,有效地绕过日食的机构。

更新3: 它似乎模型或许是蚀插头-在休息日食的能力正确地公布,以Tomcat。只有通过消除该模型或许能在一个项目,我可以得到它的正常发布一次。很烦人。

更新2: 我现在这个工作在日食。这让我很不舒服说这个但我不知道我怎么拿到它的工作从蚀或家的基础之上。这似乎是一个编译问题,而不是运行时间的问题。

更新1: 看来我得到这工作通过家建立的,但我们不知道如何。日食仍然不起作用。我唯一改变的 pom.xml 是添加这些(微不足道的?) 构成参数:

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

实际上,我担心,我有一个重复的 这个问题, ,这里的一切工作也不一致。我将保留这个问题的更新,因为我了解更多信息。

关于食,我取得了一些进展,采取的二元方面,我希望织-在这种情况下 spring-aspects.jar -和复制出来的我的类路径。然后我加入这个现在外部罐子给我 方面的道路.这样做后,蚀正确地表示了我的模型或许标记在我的代码。这很烦人,我不能就这么离开 spring-aspects.jarJava建立的路径 这是由专家为我通过家插件。由于某些原因,然而,模型或许插在看不到二进制方面,除非他们明确地加入 方面的道路.


原职: @配置是弹簧的注释,可使依赖关系注入对象的实例外弹(例如,通过休眠或一些工厂类)。

我是使用这种注先前载时织和它 大多是 的工作。偶尔我会启动并没有什么会获得注入。这个问题,催生了 这个计算器的问题.没有许多答案,但大多数建议,我尝试汇编时织而不是由于更高的可靠性。

我安装的模型或许插在用户和专家.这两个产生什么似乎是适当地编制的课程。我已经打开了一个类在一个文本编辑器之前的样aspect汇编和发现没有引用的模型或许.我打开了它最后模型或许汇编和两蚀和家产生的版本有一个参考 org.模型或许.韦弗。MethodDeclarationLineNumber.这就是为什么我要假设它是适当地编制。问题是,一旦部署,没有任何依赖获得注入。

我的弹簧 applicationContext.xml 不包括如下:

    <context:spring-configured />

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

是上述所有需要的类别标记@配置有迪做了什么?在转载时织汇编时织,我删除了 META-INF/aop.xml, <context:load-time-weaver /> 从我的 applicationContext.xml, 和春季的Tomcat织从我的 context.xml.

我怎么能调查这个问题的进一步吗?什么是可能的原因?

有帮助吗?

解决方案

它适用于我们使用编译时织入行家,尝试添加以下插件:

<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
  • 春季2.5.6
  • JPA 与 eclipselink-1.1.0

配置详情:

Spring 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>

Spring注解

@Configurable("baseEntity")
public abstract class BaseEntity

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

Java虚拟机参数

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

HistoryHandler 和 baseEntitty 的实例由 ecliselink 创建。baseEntitty 中的historyHandler 和historyHandler 中的historyDao 是通过load-timeweaving 设置的。

您可以在 Eclipse 运行配置或 Tomcats catalina.sh/bat 中设置 VM 参数。

制作@Configurable类自动装配Autowired引发NullPointerException异常,如果你不为这个注释正确地配置您的春天的领域。 请按照下列步骤进行@Configurable注解正常工作

此方法被称为的 AspectJ的构建时织入到注入弹簧豆到非弹簧制成的类

第一步是在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它将被配置的新实例(例如,具有的依赖关系注入)自动进行。

尽你蚀类路径问题而言,你可能会发现这很有用的。

m2eclipse插件 有一个可选的 究ajdt一体化.融读aspectLibraries部分的模型或许-玛文件的配置,并有助于罐子来日食的方面道路。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top