Today Aop Framework

today aop is a high-performance lightweight aop framework.

License

License

GroupId

GroupId

cn.taketoday
ArtifactId

ArtifactId

today-aop
Last Version

Last Version

1.0.5.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

Today Aop Framework
today aop is a high-performance lightweight aop framework.
Project URL

Project URL

https://github.com/TAKETODAY/today-aop
Project Organization

Project Organization

TODAY
Source Code Management

Source Code Management

https://github.com/TAKETODAY/today-aop.git

Download today-aop

How to add to project

<!-- https://jarcasting.com/artifacts/cn.taketoday/today-aop/ -->
<dependency>
    <groupId>cn.taketoday</groupId>
    <artifactId>today-aop</artifactId>
    <version>1.0.5.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/cn.taketoday/today-aop/
implementation 'cn.taketoday:today-aop:1.0.5.RELEASE'
// https://jarcasting.com/artifacts/cn.taketoday/today-aop/
implementation ("cn.taketoday:today-aop:1.0.5.RELEASE")
'cn.taketoday:today-aop:jar:1.0.5.RELEASE'
<dependency org="cn.taketoday" name="today-aop" rev="1.0.5.RELEASE">
  <artifact name="today-aop" type="jar" />
</dependency>
@Grapes(
@Grab(group='cn.taketoday', module='today-aop', version='1.0.5.RELEASE')
)
libraryDependencies += "cn.taketoday" % "today-aop" % "1.0.5.RELEASE"
[cn.taketoday/today-aop "1.0.5.RELEASE"]

Dependencies

compile (1)

Group / Artifact Type Version
cn.taketoday : today-context jar 2.1.6.RELEASE

provided (2)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.0
ch.qos.logback : logback-classic jar 1.2.3

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.23.4

Project Modules

There are no modules declared in this project.

TODAY Aop

🍎 today-aop is a high-performance lightweight aop framework

Codacy Badge Java CI

🛠️ 安装

<dependency>
    <groupId>cn.taketoday</groupId>
    <artifactId>today-aop</artifactId>
    <version>1.0.5.RELEASE</version>
</dependency>

案例

📝 使用说明

使用@Aspect标注一个切面

@Aspect
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class LogAspect {

	@AfterReturning(Logger.class)
	public void afterReturning(@Returning Object returnValue) {
		log.debug("@AfterReturning returnValue: [{}]", returnValue);
	}

	@AfterThrowing(Logger.class)
	public void afterThrowing(@Throwing Throwable throwable) {
		log.error("@AfterThrowing With Msg: [{}]", throwable.getMessage(), throwable);
	}

	@Before(Logger.class)
	public void before(@Annotated Logger logger, @Argument User user) {
		log.debug("@Before method in class with logger: [{}] , Argument:[{}]", logger, user);
	}

	@After(Logger.class)
	public Object after(@Returning User returnValue, @Arguments Object[] arguments) {
		log.debug("@After method in class");
		return returnValue.setSex("");
	}

	@Around(Logger.class)
	public Object around(@JoinPoint Joinpoint joinpoint) throws Throwable {
		log.debug("@Around Before method");
//		int i = 1 / 0;
		Object proceed = joinpoint.proceed();
		log.debug("@Around After method");
		return proceed;
	}
}

public @interface Logger {
	/** operation */
	String value() default "";
}

@Service
public class DefaultUserService implements UserService {

	@Autowired
	private UserDao userDao;

	@Logger("登录")
	@Override
	public User login(User user) {
		log.debug("login");
//		int i = 1 / 0;
		return userDao.login(user);
	}
	@Logger("注册")
	@Override
	public boolean register(User user) {
		return userDao.save(user);
	}
}
@Repository
public class UserDaoImpl implements UserDao {

	private Map<String, User> users = new HashMap<>();

	public UserDaoImpl() {
		users.put("666", new User(1, "杨海健", 20, "666", "666", "", new Date()));
		users.put("6666", new User(2, "杨海健1", 20, "6666", "6666", "", new Date()));
		users.put("66666", new User(3, "杨海健2", 20, "66666", "66666", "", new Date()));
		users.put("666666", new User(4, "杨海健3", 20, "666666", "666666", "", new Date()));
	}

	@Override
	public boolean save(User user) {
		users.put(user.getUserId(), user);
		return true;
	}
	@Override
	public User login(User user) {

		User user_ = users.get(user.getUserId());
		if (user_ == null) {
			return null;
		}
		if (!user_.getPasswd().equals(user.getPasswd())) {
			return null;
		}
		return user_;
	}
}

@Test
public void test_Login() throws NoSuchBeanDefinitionException {

	try (ApplicationContext applicationContext = new StandardApplicationContext("","")) {
		UserService bean = applicationContext.getBean(UserServiceImpl.class);
		User user = new User();
		user.setPasswd("666");
		user.setUserId("666");
		
		long start = System.currentTimeMillis();
		User login = bean.login(user);
		log.debug("{}ms", System.currentTimeMillis() - start);
		log.debug("Result:[{}]", login);
		log.debug("{}ms", System.currentTimeMillis() - start);
	}
}

📝 开源协议

请查看 GNU GENERAL PUBLIC LICENSE

Versions

Version
1.0.5.RELEASE
1.0.4.RELEASE
1.0.3.RELEASE