springmvc出现事务注解无效
旧项目使用的是spring+mvc,通过的是xml来配置。
期间出现了一个问题,事务注解无效.
通过排查发现<context:component-scan 重复扫描了两次。
还是新项目使用spring boot注入方式比较清晰。
解决spring boot项目多个类implements于同一个接口类,使用注解需要多个@Qualifier
- 业务场景
搭建DI系统定时任务调度管理使用的是Quartz。
首先通过一个主定时任务去触发其它任务的调度处理。最终是触发BaseTask的execute方法。BaseTask继承Job。
然后execute方法里通过ThirdBusinessFactory工厂类去获取相应参数获取IThirdBll接口的实例。 问题
因为Spring boot一般都是通过@Autowired去注入,从而实例然后调用,如果直接通过New实例化则里面再通过@Autowired注解会有问题。
但是如果在ThirdBusinessFactory。每个实例都写成如下将会是越来越多:123@Qualifier("A")@Autowiredprivate IThirdBll A;解决
12@Autowiredprivate List<Itest> testList;先将全部实例注解进去,再通过遍历testList寻找相应的实例。可以自定义个注解例如 TaskHandler,然后根据如下获取并加以判断。
123456789101112131415@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Inherited@Componentpublic @interface TaskHandler {String value() default "";String customer() default "";String description() default "";}TaskHandler annotation = taskHandlerClass.getAnnotation(TaskHandler.class)
Spring boot项目出现跨域问题
Spring boot项目出现跨域问题
|
|
这是配置跨域的一种方法,但出现了一种情况,定义的拦截器HandlerInterceptorAdapter preHandle方法抛出的错会有跨域问题。
解决办法
- SpringMVC开启CORS支持
- [SpringMVC 与权限拦截器冲突导致的Cors跨域设置失效问题] (https://segmentfault.com/a/1190000010348077)
|
|