Java 编译时的方面编织不会';行不通
我使用EclipseKepler,Java1.7。 下面是我的pom.xml的一部分。 正如我在maven编译期间看到的,根本没有关于编织的日志。我也没有任何错误。 方面也不起作用。 我做错了什么? 正如我在一些例子中看到的,这个pom应该可以工作。 我将AspectJ工具安装到EclipseJava 编译时的方面编织不会';行不通,java,aop,aspectj,aspect,aspectj-maven-plugin,Java,Aop,Aspectj,Aspect,Aspectj Maven Plugin,我使用EclipseKepler,Java1.7。 下面是我的pom.xml的一部分。 正如我在maven编译期间看到的,根本没有关于编织的日志。我也没有任何错误。 方面也不起作用。 我做错了什么? 正如我在一些例子中看到的,这个pom应该可以工作。 我将AspectJ工具安装到Eclipse <plugin> <groupId>org.codehaus.mojo</groupId> &l
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.7</version>
<configuration>
<showWeaveInfo>true</showWeaveInfo>
<source>${compiler.version}</source>
<target>${compiler.version}</target>
<Xlint>ignore</Xlint>
<complianceLevel>${compiler.version}</complianceLevel>
<encoding>UTF-8</encoding>
<verbose>true</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>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
此外,还有maven clean compile
输出:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for myproject:war:0.0.1-SNAPSHOT
[WARNING] The expression ${build.sourceDirectory} is deprecated. Please use ${project.build.sourceDirectory} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ myproject ---
[INFO] Deleting /Users/user1/git/myproject/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) @ myproject ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 41 source files to /Users/user1/git/myproject/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.007 s
[INFO] Finished at: 2015-02-16T10:00:23-08:00
[INFO] Final Memory: 12M/245M
[INFO] ------------------------------------------------------------------------
您是否创建了一个aop.xml并放置在Meta inf文件夹下,在该aop.xml中是否放置了需要编织的类的包详细信息?您是否创建了一个aop.xml并放置在Meta inf文件夹下,在该aop.xml中是否放置了需要编织的类的包详细信息?您是否创建了一个aop.xml并放置在Meta inf文件夹下创建了一个aop.xml并放置在Meta inf文件夹下,在该aop.xml中您是否放置了需要编织的类的包详细信息?您是否创建了一个aop.xml并放置在Meta inf文件夹下,在该aop.xml中您是否放置了需要编织的类的包详细信息?您的Maven日志显示没有aspectj maven插件正在执行的迹象,因此没有编织。我假设您已将插件配置放入
部分,但未引用
部分中已配置的插件。这可以解释缺少插件输出的原因。即,您需要这样做:
org.codehaus.mojo
aspectj maven插件
1.7
(...)
(...)
(...)
org.codehaus.mojo
aspectj maven插件
您的Maven日志没有显示任何正在执行aspectj Maven插件的迹象,因此没有编织。我假设您已将插件配置放入
部分,但未引用
部分中已配置的插件。这可以解释缺少插件输出的原因。即,您需要这样做:
org.codehaus.mojo
aspectj maven插件
1.7
(...)
(...)
(...)
org.codehaus.mojo
aspectj maven插件
您的Maven日志没有显示任何正在执行aspectj Maven插件的迹象,因此没有编织。我假设您已将插件配置放入
部分,但未引用
部分中已配置的插件。这可以解释缺少插件输出的原因。即,您需要这样做:
org.codehaus.mojo
aspectj maven插件
1.7
(...)
(...)
(...)
org.codehaus.mojo
aspectj maven插件
您的Maven日志没有显示任何正在执行aspectj Maven插件的迹象,因此没有编织。我假设您已将插件配置放入
部分,但未引用
部分中已配置的插件。这可以解释缺少插件输出的原因。即,您需要这样做:
org.codehaus.mojo
aspectj maven插件
1.7
(...)
(...)
(...)
org.codehaus.mojo
aspectj maven插件
我在aspect类中使用了注释:@Around(“execution(public filter.RolesFilter.doFilter(…)”)@Vaidy:您的答案没有意义。问题是关于编译时编织,但aop.xml仅用于加载时编织。@Battle\u Slug:Around建议的切入点语法是错误的。您不指定方法返回类型。因此,您应该会看到AspectJ编译器错误。例如,此语法是正确的:@Around(“execution(public*filter.RolesFilter.doFilter(…)”
——请注意额外的*
。包名可能仍然有问题,我不能不看你的代码。@kriegaex我添加了我的方面的代码。事实上,我没有任何错误。就像我的项目中没有AspectJ一样。我在方面类中使用了注释:@Around(“execution(public filter.RolesFilter.doFilter(…)”)@Vaidy:你的答案没有意义。问题是关于编译时编织,但aop.xml仅用于加载时编织。@Battle\u Slug:Around建议的切入点语法是错误的。您不指定方法返回类型。因此,您应该会看到AspectJ编译器错误。例如,此语法是正确的:@Around(“execution(public*filter.RolesFilter.doFilter(…)”
——请注意额外的*
。包名可能仍然有问题,我不能不看你的代码。@kriegaex我添加了我的方面的代码。事实上,我没有任何错误。就像我的项目中没有AspectJ一样。我在方面类中使用了注释:@Around(“execution(public filter.RolesFilter.doFilter(…)”)@Vaidy:你的答案没有意义。问题是关于编译时编织,但aop.xml仅用于加载时编织。@Battle\u Slug:Around建议的切入点语法是错误的。您不指定方法返回类型。因此,您应该会看到AspectJ编译器错误。例如,此语法是正确的:@Around(“execution(public*filter.RolesFilter.doFilter(…)”
——请注意额外的*
。包名可能仍然有问题,我不能不看你的代码。@kriegaex我添加了我的方面的代码。事实上,我没有任何错误。就像我的项目中没有AspectJ一样。我在方面类中使用了注释:@Around(“execution(public filter.RolesFilter.doFilter(…)”)@Vaidy:你的答案没有意义。问题是关于编译时编织,但是aop。
package filter;
import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class RolesFilter implements Filter {
Logger logger = Logger.getLogger(RolesFilter.class.getName());
public RolesFilter() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException {
logger.info("This is logger message");
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
HttpSession session = req.getSession();
String reqURI = req.getRequestURI();
String userName = (String) session.getAttribute("username");
Character role = (Character) session.getAttribute("role");
try {
if (role != null && role.charValue() == 'A') {
if (reqURI.indexOf("/admin/") >= 0) {
chain.doFilter(request, response);
} else {
res.sendRedirect(req.getContextPath()
+ "/view/roles/admin/home.xhtml");
}
} else if (role != null && role.charValue() == 'B') {
if (reqURI.indexOf("/biller/") >= 0) {
chain.doFilter(request, response);
} else {
res.sendRedirect(req.getContextPath()
+ "/biller.xhtml");
}
} else if (role != null && role.charValue() == 'C') {
if (reqURI.indexOf("/customer/") >= 0) {
chain.doFilter(request, response);
} else {
res.sendRedirect(req.getContextPath()
+ "/customer.xhtml");
}
} else {
res.sendRedirect(req.getContextPath()
+ "/login.xhtml");
}
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for myproject:war:0.0.1-SNAPSHOT
[WARNING] The expression ${build.sourceDirectory} is deprecated. Please use ${project.build.sourceDirectory} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ myproject ---
[INFO] Deleting /Users/user1/git/myproject/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) @ myproject ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 41 source files to /Users/user1/git/myproject/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.007 s
[INFO] Finished at: 2015-02-16T10:00:23-08:00
[INFO] Final Memory: 12M/245M
[INFO] ------------------------------------------------------------------------