- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近一直在一个非常简单的应用程序上尝试 Spring 的 AOP 功能,并且我坚持在适当的时间运行该方法,这意味着该部分中定义的方法应该在
中定义的方法之后运行在我的代码中,这两个方法都在主方法中定义并在主方法之前运行。当然,在后者中这是正常的,但在后者中则不然。
预期输出应该是:
HERE IS THE AOP BEFORE
From App ran 5k
HERE IS THE AOP After
我当前的输出是:
HERE IS THE AOP BEFORE
HERE IS THE AOP After
From App ran 5k
知道为什么吗?
Pom.xml:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
springDemo
FirstSpringDemo
1.0-SNAPSHOT
jar
FirstSpringDemo
http://maven.apache.org
UTF-8
src
trình biên dịch maven
3.1
1.8
1.8
org.springframework
spring-context
4.3.1.RELEASE
org.springframework
spring-aop
4.3.1.RELEASE
org.springframework
spring-webmvc
4.3.1.RELEASE
org.springframework
spring-web
4.3.1.RELEASE
javax.servlet
jstl
1.2
junit
junit
3.8.1
test
junit
junit
4.12
cglib
cglib
2.2
org.aspectj
aspectjweaver
1.6.11
我的主类,称为 App:
package main.java.springDemo;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Coach trackCoach = context.getBean("myTrackCoach", Coach.class);
System.out.println(" From App " + trackCoach.getDailyWorkout());
}
}
TrackerCoach.java
package main.java.springDemo;
public class TrackCoach implements Coach {
@Ghi đè
public String getDailyWorkout() {
return "Go and run 5k";
}
}
SayAOP.java
package main.java.springDemo;
public class SayAOP {
public void shoutAOPBefore() {
System.out.println("HERE IS THE AOP BEFORE");
}
public void shoutAOPAfter(){
System.out.println("HERE IS THE AOP After");
}
}
教练.java
package main.java.springDemo;
public interface Coach {
String getDailyWorkout();
}
applicationContext.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
class="main.java.springDemo.TrackCoach">
class="main.java.springDemo.SayAOP">
1 Câu trả lời
Đó là bởi vìtrackCoach.getDailyWorkout()
作为 System.out.println 参数调用,因此首先调用 before,然后调用 trackCoach.getDailyWorkout(),然后调用 after,最后调用 System.out。尝试例如:
public class TrackCoach implements Coach {
@Ghi đè
public String getDailyWorkout() {
System.out.println("Go and run 5k");
return "Go and run 5k";
}
}
你会看到会发生什么。
关于java - Spring AOP aop :after running early,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42963308/
“Fail Early”是什么意思,在什么情况下这种方法最有用,你什么时候会避免这种方法? 最佳答案 本质上,快速失败 (又名 尽早失败 )是对您的软件进行编码,使得 当出现问题时,软件会尽快并尽可能
嗨,我正在尝试安装 Homebrew (MacOS Catalina) 在他们的官方网页上运行命令后,我收到以下错误。 在此先感谢您的帮助。 Cloning into '/usr/local/Home
在尝试了解有关计算表达式如何工作的更多信息时,我尝试编写一个构建器,该构建器在评估 if 的 then block 后跳过表达式的其余部分> 语句,因此工作流本身将评估为 true。如果没有任何 if
在下面的函数中,是什么让 try: 提前退出?如果我将相同的代码放在 def block 之外,它就可以正常工作。 tiles = ['095D', '094M'] in_file = 'in_fil
我正在使用 Keras 训练神经网络,使用提前停止。然而,在训练时,网络很早就达到了验证损失异常低的点,一段时间后就变平了,就像这样。 当使用 patience = 50 的提前停止时,验证损失趋于平
我想从 github 上克隆一个项目到我的电脑上 D:\Projects> git clone https://github.com/***/***.git 但是在下载的时候,出现了几个致命的错误:
我正在使用Haskeline包,我想在做任何事情之前从命令行连续获取三个字符串,并且我想出了对我来说似乎是一个巧妙的解决方案。但我确信可能有更好的方法来做到这一点。我正在寻找使用 Haskeline
This question already has answers here: Using return inside a lambda? (5个答案) 1年前关闭。 在Runnable块中,我想执行
这个问题已经有答案了: Python Tkinter Error, "Too Early to Create Image" (1 个回答) 已关闭 4 年前。 我正在尝试创建一个图像库并从 tkint
在我的 AngularJS Controller 中,我调用了我的数据服务方法,它生成了一个 $http调用以获取页面显示所需的数据。 appDataService.getById() .succ
这个问题在这里已经有了答案: How to properly break out of a promise chain? (3 个答案) 关闭 7 年前。 我最近开始用 coffeescript/j
我是 winsock2 的新手,并为我试图用来向我在同一台计算机上运行的客户端(连接到 127.0.0.1 的客户端)发送字符串的服务器编写了以下代码与服务器相同的端口设置为监听)。 如果重要的话,我
我的问题很简单:我正在等待截取 MKMapView 的屏幕截图,并且我只想在加载 map 后执行此操作。不幸的是,这个委托(delegate)方法几乎总是在 map 实际加载之前被调用。如果我幸运的话
考虑以下设置: 啊.h #define A 5 #define B A #undef A #define A 3 交流 #include "a.h" #include int main() {
我正在运行安装了 Git(来自 Ubuntu 包管理器的最新版本)的 Ubuntu (9.10) 服务器。通过 SSH 访问 Git。在 Windows 机器上,我使用 Cygwin 来推送/pull
我有一个需要微秒延迟的驱动程序。为了创建这种延迟,我的驱动程序使用了内核的 udelay 函数。具体来说,有一次调用 udelay(90): iowrite32(data, addr + DATA_O
425 “太早”状态码的描述: Indicates that the server is unwilling to risk processing a request that might be re
如果是前向渲染,那么FS执行的次数是(numberOfAllPixels * numberOfLights),如果是延迟渲染,那么FS执行的次数是(numberOfVisiblePixels * nu
在 Web 编程时经常发生在我身上的事情:我想运行一个有可能失败的操作。如果失败,我想向客户端发送 500。但通常,我只想继续执行一系列步骤。 doSomeWebStuff :: SomeWebMon
我正在使用 Keras。我正在训练我的神经网络并使用 Early Stopping。我的耐心是 10,验证损失最低的纪元是 15。我的网络运行到 25 个纪元然后停止,但是我的模型是 25 个纪元而不
Tôi là một lập trình viên xuất sắc, rất giỏi!