我编写了一个简单的Spring2.5应用来演示/测试AOP; 具体来说,我想记录特定包中每个类的每个方法的进入和退出.这就是我所拥有的......
(注意:我正在使用注释控制器;我省略了与aop没有直接关系的细节,因为我的基本设置工作正常 - 我只包含与aop相关的详细信息 - 如果你需要了解更多,请告诉我)
applicationContext.xml:
(...)
<bean id="loggerInterceptor" class="aspect.LoggerInterceptor" />
(...)
Run Code Online (Sandbox Code Playgroud)
dispatcher-servlet.xml:
(...)
<aop:aspectj-autoproxy proxy-target-class="true" />
(...)
Run Code Online (Sandbox Code Playgroud)
HomeController.java:
public class HomeController() {
public HomeController() { }
public ModelAndView get() {
System.out.println("In HomeController#get()...");
this.somePrivateMethod();
this.somePublicMethod();
return new ModelAndView( "home" );
}
private void somePrivateMethod() {
System.out.println("In HomeController#somePrivateMethod()...");
}
public void somePublicMethod() {
System.out.println("In HomeController#somePublicMethod()...");
}
}
Run Code Online (Sandbox Code Playgroud)
LoggerInterceptor.java:
public class LoggerInterceptor {
@Pointcut("execution(* controller.*.*(..))")
private void anyOperationInControllerPackage() {
/* nothing to do here;
* this just defines that we …Run Code Online (Sandbox Code Playgroud) 正如这里提到的,我有一点时间让我的小型Spring-Boot项目"正确"部署到Glassfish.它使用嵌入式Tomcat运行良好,但是一旦我尝试将其移动到我的组织环境(Glassfish 3.1.2)中,我就会遇到一些奇怪的行为.
认为这是我的代码,我回到了经过时间考验的"Hello World" - 方法,并在Spring的博客上建立了一个超级基本的应用程序.
当我一起去的时候,我确实做了一些非常小的偏差,但是根本没有任何应该影响这个应用程序的东西.
我发现的唯一一个主要偏差是我发现我无法从"spring-boot-starter-web"中排除"spring-boot-starter-tomcat" - 当我尝试这个时,我在STS中遇到了2个错误"Markers" "-标签:
The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletContext. Fix the build path then try building this project
The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files Application.java
Run Code Online (Sandbox Code Playgroud)
如果我清理了STS项目,然后运行Maven Clean,更新,安装Install目标会出现以下错误:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure [ERROR] /Users/brandon_utah/Utah Development/sts_workspaces/NidTools Rebooted/test/src/main/java/test/Application.java:[13,8] cannot access javax.servlet.ServletException [ERROR] class file …Run Code Online (Sandbox Code Playgroud)