提交 853bbdd5 编写于 作者: 希川's avatar 希川

<feat>: 自动扫描 Bean 对象, 单元测试补充

上级 7ca6c526
......@@ -9,6 +9,7 @@ import cn.noexception.container.aop.aspectj.AspectJExpressionPointcutAdvisor;
import cn.noexception.container.aop.framework.ProxyFactory;
import cn.noexception.container.aop.framework.ReflectiveMethodInvocation;
import cn.noexception.container.aop.framework.adapter.MethodBeforeAdviceInterceptor;
import cn.noexception.container.context.support.ClassPathXmlApplicationContext;
import cn.noexception.test.bean.IUserService;
import cn.noexception.test.bean.UserServiceBeforeAdvice;
import cn.noexception.test.bean.UserServiceInterceptor;
......@@ -101,4 +102,29 @@ public class AopTest {
String result = proxy.queryUserInfo();
System.out.println("测试结果:" + result);
}
@Test
public void test_property() {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-property.xml");
IUserService userService = applicationContext.getBean("userService", IUserService.class);
System.out.println("测试结果: " + userService);
}
@Test
public void test_scan() {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:spring-scan.xml");
IUserService userService = applicationContext.getBean("userService", IUserService.class);
System.out.println("测试结果:" + userService.queryUserInfo());
}
}
package cn.noexception.test.bean.impl;
import cn.noexception.container.factory.stereotype.Cube;
import cn.noexception.test.bean.IUserService;
import java.util.Random;
......@@ -10,7 +11,11 @@ import java.util.Random;
* @author 吕滔
* @Date 2021/11/3 17:01
*/
@Cube("userService")
public class UserService implements IUserService {
private String token;
@Override
public String queryUserInfo() {
try {
......@@ -31,4 +36,17 @@ public class UserService implements IUserService {
return "注册用户:" + userName + " success! ";
}
@Override
public String toString() {
return "UserService#token = { " + token + " }";
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context">
<bean class="cn.noexception.container.factory.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:token.properties"/>
</bean>
<bean id="userService" class="cn.noexception.test.bean.impl.UserService">
<property name="token" value="${token}"/>
</bean>
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context">
<context:component-scan base-package="cn.noexception.test.bean"/>
</beans>
\ No newline at end of file
token=RejDlI78hu223Opo983Ds
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册