1、注解对比

Solon Spring JSR 330
@Inject * @Autowired @Inject 注入Bean(by type)
@Inject("name") @Qualifier +
@Autowired
@Qualifier +
@Inject
注入Bean(by name)
@Inject("${name}") @Value("${name}") - 注入配置
@Component @Component @Named 托管组件
@Singleton @Scope(“singleton”) @Singleton 单例(Solon 默认是单例)
@Singleton(false) @Scope(“prototype”) - 非单例
@Init * @PostConstruct - 构造完成并注入后的初始化
@Configuration @Configuration - 配置类
@Bean @Bean 配置组件
@Mapping @RequestMapping... - 映射
@Controller @Controller
@RestController
- 控制器类(有类代理)
@Service @Service - 服务类(有类代理)
@Dao @Dao - 数据访问类(有类代理)
@Import @Import +
@ComponentScan
- 组件导入或扫描
  • Solon 的 @Inject 算是: Spring 的@Value、@Autowired、@Qualifier 三者的结合,但又不完全等价
  • Solon 的 @Import 算是:Spring 的@Import、@ComponentScan 两者的结合,即有导入功能也有扫描功能
  • Solon 托管的 Bean 初始化顺序:new() - > @Inject - > @Init
  • 注1:Method@Bean,只执行一次(只在 @Configuration 里有效)
  • 注2:@Inject 的参数注入,只在Method@Bean上有效
  • 注3:@Inject 的类型注入,只在@Configuration类上有效

2、部分用例说明

Solon 强调有节制的注解使用,尤其对于增加处理链路的操会比较节制。

  • @Component(组件托管:基于 name 或者 类型;且只记录第一次的注册)
@Component
public class UserService{
@Db("db1") //@Db为第三方扩展的注入注解
BaseMapper<User> mapper; UserModel getUser(long puid){
return db1.selectById(puid);
}
} /* @Component("userService")
public class UserService{
@Db("db1")
BaseMapper<User> mapper; UserModel getUser(long puid){
return db1.selectById(puid);
}
} */
  • @Controller
@Singleton(false)    //非单例注解
@Controller
public class UserController{
@Inject("${message.notnull}")
String message; @Inject
UserService userService @Mapping("/user/{puid}")
public Object user(Long puid){
if(puid == null){
return message;
}
return userService.getUser(puid);
}
}
  • @Configuration
@Configuration
public class Config {
@Bean("db1")
public DataSource db1(@Inject("${test.db1}") HikariDataSource ds) {
return ds;
}
} //系统异常监听(这个系统会发的,还可以监听不同的异常)
//
@Configuration
public class ThrowableListener implements EventListener<Throwable> {
WaterLogger log = new WaterLogger("rock_log"); @Override
public void onEvent(Throwable err) {
Context ctx = Context.current(); if (ctx != null) {
String _in = ONode.stringify(ctx.paramMap()); log.error(ctx.path(), _in, err);
}
}
}

Solon Web 开发,十四、与Spring、Jsr330的常用注解对比的更多相关文章

  1. Solon Web 开发,四、请求上下文

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  2. Solon Web 开发,七、视图模板与Mvc注解

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  3. java web开发入门四(spring)基于intellig idea

    spring 1.spring简介 Spring框架,可以解决对象创建以及对象之间依赖关系的一种框架. 且可以和其他框架一起使用:Spring与Struts,  Spring与hibernate (起 ...

  4. Solon Web 开发,十二、统一的渲染控制

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  5. Solon Web 开发

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  6. Solon Web 开发,一、开始

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  7. Solon Web 开发,二、开发知识准备

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  8. Solon Web 开发,五、数据访问、事务与缓存应用

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

  9. Solon Web 开发,六、过滤器、处理、拦截器

    Solon Web 开发 一.开始 二.开发知识准备 三.打包与运行 四.请求上下文 五.数据访问.事务与缓存应用 六.过滤器.处理.拦截器 七.视图模板与Mvc注解 八.校验.及定制与扩展 九.跨域 ...

随机推荐

  1. js实现数组去重的方式(7种)

    JS数组去重的方式 例:将下面数组去除重复元素(以多种数据类型为例) const arr = [1, 2, 2, 'abc', 'abc', true, true, false, false, und ...

  2. python enumerate枚举用法总结

    enumerate()说明 enumerate()是python的内置函数enumerate在字典上是枚举.列举的意思对于一个可迭代的(iterable)/可遍历的对象(如列表.字符串),enumer ...

  3. 【进阶】uniapp复现微信相册功能之【图视频编辑 + 压缩】

    基于uniapp + vue实现微信相册,在实现了微信相册的基础上增加以下功能 1: 图片编辑 2: 视频编辑 3: 文件压缩 技术实现 开发环境:HbuilderX + nodejs 技术框架:un ...

  4. AcWing822. 走方格

    题目 给定一个\(n×m\)的方格阵,沿着方格的边线走,从左上角\((0,0)\)开始,每次只能往右或者往下走一个单位距离,问走到右下角\((n,m)\)一共有多少种不同的走法. 输入格式 共一行,包 ...

  5. IDEA常用设置及插件

    设置 1.设置打开后不直接进入项目 IDEA默认打开时会直接进入上次打开的目录,有的时候加载很长时间,但这个时候可能我们并不是要打开这个项目,这里有一个设置,在如图的位置,去掉勾选,即可设置打开后不直 ...

  6. maven中pom文件中scope的作用

    Dependency Scope  <dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: compile 默认 ...

  7. SpringBoot整合quartz实现动态启动,停止定时任务功能

    注意:这个方法当程序重启之后会失效,所以必须将定时任务持久化到数据库,然后程序启动的时候重新把数据库的定时任务加载到quartz中 springboot程序启动初始化代码参考:https://www. ...

  8. 解决appt.exe finished with non- zero exit value 1问题

    解决appt.exe finished with non- zero exit value 1问题 最近使用Android Studio时,经常遇到appt.exe finished with non ...

  9. 【LeetCode】1060. Missing Element in Sorted Array 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 日期 题目地址:https://leetcode ...

  10. Codeforces 872B:Maximum of Maximums of Minimums(思维)

    B. Maximum of Maximums of Minimums You are given an array a1, a2, ..., an consisting of n integers, ...