Spring自学第二天

1.基于注解的配置bean
  组件扫描(component scanning):Spring能够从classpath下自动扫描,侦测和实例化具有特定注解的组件
  组件包括:
  -@Component:基本注解,表示一个受Spring管理的组件
  -@Respository:标识持久层组件
  -@Service:标识服务层(业务层)组件
  -@Controller:标识表现层组件
  使用注解后,还需要在Spring配置文件中声明<context:component-scan>
  -base-package属性指定一个需要扫描的基类包,Spring容器将会扫描这个基类包及其自爆中的所有类
  -当需要扫描多个包时,使用逗号分隔
例如:一个基于注解的Bean
@Component   //受Spring管理的组件
public class testObject {
}  
新建一个接口:UserRespository
public interface UserRepository {
void save();
}
这个接口Impl,持久层
@Repository(value="userRespository")
public class UserRepositoryImpl implements UserRepository {
@Override
public void save() {
// TODO Auto-generated method stub
        System.out.println("UserRepository begin~~~~~~");
}
}  
写一个业务层
@Service
public class UserService {
public void add(){
System.out.println("UserService begin~~~~");
}
}
写一个Controller
@Controller
public class UserController {
public void executable(){
System.out.println("UserController begin");
}
}  
配置文件中配置自动扫描的包:
<context:component-scan base-package="cn.spring.study03.*" />  
-如果仅希望扫描特定的类而非基包下的所有类,可使用resource-pattern属性过滤特定的类,示例:
<context:component-scan base-package="com.spring.beans"
    resource-pattern="repository/*.class"/>
-<context:include-filter>子节点表示要包含的目标类
-<context:exclude-filter>子节点表示要排除在外的目标类
支持多种类型的过滤表达式
 annotation   com.spring.XxxAnnotation  所有标注了XxxAnnotation的类,该类型采用目标类是否标注了某个注解进行过滤
 assinable    com.spring.XxxService    所有继承或扩展XxxService的类,该类型采用目标类是否继承或扩展某个特定类进行过滤
 aspectj   com.spring.*Service+   所有类名以Service结束的类及继承或扩展它们的类。该类型采用Aspectj表达式进行过滤
 regex com.spring.anno...  所有com.spring.anno包下的类,该类型采用正则表达式根据类的类名进行过滤
 custom  com.spring.XxxTypeFilter  采用XxxTypeFilter通过代码的方式定义过滤规则。该类必须实现org.springframework.core.type.TypeFilter接口
<!--context:exclude-filter 子节点指定排除哪些指定表达式组件-->
<context:component-scan base-package="com.spring.annotation">
    <context:exclude-filter type="annotation"
        expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
注意:默认情况下ClassPathBeanDefinitionScanner会注册对@Component、@ManagedBean的bean进行扫描,因为use-default-filter默认为true
假设在一个包下包含多种注解的Bean,这里仅仅设置了需要扫描到@Controller,这是可以通过将use-default-filter设置为false即可
2.泛型依赖注入,是spring 4.0引入的新功能
一个典型的例子,首先创建BaseRepository<T>和BaseService<T>  
public class BaseRepository<T> {
}  
public class BaseService<T> {
@Autowired
protected BaseRepository<T> repository;
public void add(){
System.out.println("add...");
System.out.println(repository);
}
}  
在创建UserRepository继承BaseRepository,和UserService继承BaseService,让他们交给IOC容器处理
@Repository
public class UserRepository extends BaseRepository<User>{



@Service
public class UserService extends BaseService<User>{



配置文件即可  

  
1. 内容概要 本项目是一个支持科学函数的命令行计算器,兼容 C++98 标准。它实现了中缀表达式词法分析、后缀表达式转换与求值,支持常见数学运算(如幂、三角函数、对数等)与括号优先级解析。程序还提供了角度版三角函数、角度与弧度互转功能,并支持函数调试输出与函数演示模式。 2. 适用人群 * C++ 初中级学习者,特别是希望深入理解表达式求值机制者 * 需要一个可扩展的计算引擎的项目开发者 * 想通过项目实践词法分析、调度场算法、数学函数封装的开发者 * 高校学生课程设计、编译原理实践者 3. 使用场景及目标 * 实现中缀表达式的完整求解器,支持函数嵌套、优先级与结合性处理 * 提供角度与弧度版本的三角函数,以适应不同输入偏好 * 演示中缀转后缀过程,辅助编程教育与算法教学 * 提供科学函数辅助计算,如 `log`, `sqrt`, `abs`, `exp`, `ceil`, `floor` 等 4. 其他说明 * 支持函数:sin, cos, tan(弧度);sind, cosd, tand(角度) * 支持函数嵌套,如 `sin(deg2rad(30))` * 支持操作符:+, -, \*, /, ^, \*\*(幂运算)与括号优先级 * 所有函数均通过 map 注册,方便扩展与自定义 * 输入 `help` 查看支持函数,`demo` 观看转后缀过程,`quit` 退出程序 * 提示用户避免使用 `°` 符号,推荐使用角度函数代替 * 可通过 `g++ calculator.cpp -o calculator -lm` 编译(需链接数学库)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值