背景 最近项目要上线,需要开发一个数据迁移程序.程序的主要功能就是将一个数据库里的数据,查询出来经过一系列处理后导入另一个数据库.考虑到开发的方便快捷.自然想到用spring和mybatis整合一下.甚至用mybatis的自动代码生成,可以省下大量dao层的开发. 整合的坑 之前的项目:以前也有过这种类似的程序,就把spring和mybatis整合的配置直接拿来修改下用.之前的整合配置是这样子的: 1.考虑到数据库url.用户名密码的可配置性,将这些信息放入properties文件.在sprin…
今天看了一下Spring Boot的run函数运行过程,发现它调用了Context中的refresh函数.所以先分析一下Spring context的refresh过程,然后再分析Spring boot中run的流程. 首先我们找到spring-context组件的AbstractApplicationContext类下的refresh函数: @Override public void refresh() throws BeansException, IllegalStateException…
一.场景分析 最近做项目遇到了一个很奇怪的问题,大致的业务场景是这样的:我们首先设定两个事务,事务parent和事务child,在Controller里边同时调用这两个方法,示例代码如下: 1.场景A: @RestController @RequestMapping(value = "/test") public class OrderController { @Autowired private TestService userService; @GetMapping public…
部署spring boot + Vue遇到的坑(权限.刷新404.跨域.内存) 项目背景是采用前后端分离,前端使用vue,后端使用springboot. 工具 工欲善其事必先利其器,我们先找一个操作Linux系统的工具极力推荐FinalShell. 一眼看过去是不是感觉很方便,对内存.CPU的监控也可以实时看到,访问目录更是方便,对于Linux小白来说简直是神兵利器. 好了,我要开始入坑了. 问题一:权限不够 把vue包放到tomcat->webapps->ROOT目录下. 启动tomcat:…
学习使用Spring.NET中的时候,写了一个Demo,在运行时报了一个错误:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常. 重新整理思绪,网上疯狂搜索引发该错误的原因,一小时过后,以绝望告终. 开发环境:VS2012,Spring.NET版本1.3.2,控制台Demo 无意中将App.Config中的一段代码删掉后可以运行通过了…… <startup> <supportedRuntime version="v4.0&…
Spring context:component-scan中使用context:include-filter和context:exclude-filter XML: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springfram…
Spring context:component-scan代替context:annotation-config XML: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/bean…
一.场景分析 最近做项目遇到了一个很奇怪的问题,大致的业务场景是这样的:我们首先设定两个事务,事务parent和事务child,在Controller里边同时调用这两个方法,示例代码如下: 1.场景A: 这里其实是分别执行了两个事物,执行的结果是两个方法都可以插入数据!如下: 2.场景B: 修改上述代码如下: Propagation.REQUIRES_NEW的含义表示:如果当前存在事务,则挂起当前事务并且开启一个新事物继续执行,新事物执行完毕之后,然后在缓刑之前挂起的事务,如果当前不存在事务的话…
Spring <context:component-scan>标签作用有很多,最基本就是 开启包扫描,可以使用@Component.@Service.@Component等注解: 今天要作为发现,记录该标签的属性 use-default-filters 以及子标签 include-filter使用方式 : use-default-filters 默认true,默认会扫描@Component.@Controller.@Service.@Repository注解,因为这些注解都可以说是@Compo…
使用web.xml方式加载Spring时,获取Spring context的两种方式: 1.servlet方式加载时: [web.xml] <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param>…
spring版本:4.3.13 ActiveMq版本:5.15 ======================================================== spring整合activeMQ,pom.xml文件缺架包,启动报错: [springDemo][INFO] [2017-12-11 14:54:57] org.springframework.web.context.ContextLoader.initWebApplicationContext(304) | Root…
今天介绍一下大家常见的一个单词 context 应该怎么去理解,正确的理解它有助于我们学习 spring 以及计算机系统中的其他知识. 1. context 是什么 我们经常在编程中见到 context 这个单词,当然每个人有每个人的理解,它被理解为:上下文.容器等等.我想说的是,context 理解为上下文最为合适.为什么呢?我以一个在计算机系统的例子来解释一下. 在计算机系统中,进程执行时有进程上下文,如果进程在执行的过程中遇到了中断,CPU 会从用户态切换为内核态(当然这个过程用户进程是感…
这里用到了placeholder特有的一个语言或者将表达形式:${},spring in action 描述如下: In spring wiring ,placeholder values are property names wrapped with ${...},as an exampl,you can resolve the constructor arguments for a BlankDisc in xml like this : <bean id="sgtPeppers&qu…
今天在配置多配置文件的时候偶然发现如果我使用   <context:property-placeholder location="classpath:filePath.properties"/> 这个进行多行编写配置文件的时候会出现后面那个文件出现读取不到的问题 <context:property-placeholder location="classpath:jdbc.properties"/> <context:property-p…
这里的注解是指@PropertySource这个注解.用@PropertySource这个注解加载.properties文件. 案例的目录结构如下: student.properties的代码如下: #用配置文件的形式,避免注入属性值的硬代码化. name=AbrahamLincoln age=21 Student的代码如下: package com.advancedWiring.ambiguityIniAutowiring2; import org.springframework.beans.…
背景 工作中负责的一套计费系统需要开发一个新通知功能,在扣费等事件触发后发送MQ,然后消费MQ发送邮件或短信通知给客户.因为有多套环境,测试时需要知道是从哪套环境发出的邮件,又不想维护多套通知模板,因此就打算在各环境的properties中声明不同的title前缀,实现类似[DEV]您的xx月账单.[TEST]您的xx月账单的效果,但是这个前缀需要在生产环境中去掉,因此我想到用Spring @Value的默认值来实现,伪代码如下: @Value("${notice.mail.titlePrefi…
一.搭建spring boot环境 maven工程 pom文件内容 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-…
问题: 有些参数在某些阶段中是常量,这些参数在不同阶段之间又往往需要改变,如: 在开发阶段我们连接数据库时的url,username,password等信息 分布式应用中client端的server地址,端口等 解决方案: Spring3中我们可以使用spring3中提供的<context:property-placeholder/>,在数据库配置文件中可以这样写: 1.配置数据库相关参数 <context:property-placeholder location="clas…
情景: 今天想把一个web应用中的上传路劲更改一下 于是就在配置文件作了如下变动: <bean id="uploadServelt" class="com.xxxx.servlet.UploadServlet" scope="request" autowire="byType"> <property name="savePath" ><value>"C:\\Us…
<context:annotation-config> 和 <context:component-scan>的区别 Difference between <context:annotation-config> vs <context:component-scan> <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面…
<context:annotation-config> 与<context-component-scan> 的作用 <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解. <context:component-scan>除了具有<context:annotation-config>的功能之外,<conte…
基本配置 <cache:annotation-driven cache-manager="cacheManager"/> <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"> <property name="caches"> <set> <bean clas…
今天照着书,试着配了AOP(全注解),结果踩了各种坑,后来参考书附带的源码,终于走出来了,现在总结一下 除了spring的jar包以外,还需要导入以下包: 1.Spring核心配置文件beans.xml(这里是大坑) <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi…
上午 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerjava.lang.IllegalArgumentException at org.springframework.cont…
转自:http://www.cnblogs.com/leiOOlei/p/3713989.html <context:annotation-config> 和 <context:component-scan>的区别 <context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean(无论是通过xml的方式还是通过package sanning的方式)上面的注解. <context:component-scan>除了…
Spring 中在使用注解(Annotation)会涉及到< context:annotation-config> 和 < context:component-scan>配置,下面就对这两个配置进行诠释. 1.context:annotation-config < context:annotation-config> 是用于激活那些已经在spring容器里注册过的bean上面的注解,也就是显示的向Spring注册 1.AutowiredAnnotationBeanPos…
(此文转载:http://www.cnblogs.com/brolanda/p/4265597.html) 一.先说ServletContext javaee标准规定了,servlet容器需要在应用项目启动时,给应用项目初始化一个ServletContext作为公共环境容器存放公共信息.ServletContext中的信息都是由容器提供的. 举例: 通过自定义contextListener获取web.xml中配置的参数 1.容器启动时,找到配置文件中的context-param作为键值对放到Se…
在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类注册为bean 注意:如果配置了<context:component-scan>那么<context:annotation-config/>标签就可以不用再xml中配置了,因为前者包含了后者.另外<context:annotation-config/>还提供了两个子标签 1…
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor.CommonAnnotationBeanPostProcessor. PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostPr…
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是向 Spring 容器注册 AutowiredAnnotationBeanPostProcessor.CommonAnnotationBeanPostProcessor. PersistenceAnnotationBeanPostProcessor 以及 RequiredAnnotationBeanPostProcessor 这 4 个BeanPostProc…