使用idea中的Live Templates自定义自动生成Spring所需的XML配置文件格式

文章目录


一、引言&问题描述

在使用Spring来管理对象时,我们需要创建Spring的配置文件applicationContext.xml,如下图位置:

  1. 在resources目录下选择new->File 或 使用idea自带模板new->XML Configuration File->Spring Config
  1. 创建applicationContext.xml
  1. 我们发现idea帮助我们生成了一些Spring所需的xml文件配置,但是还是缺一些配置,比如AOP的配置。
  1. 此时就可以考虑使用idea中的Live Templates来自定义我们Spring所需的XML配置文件格式

二、解决方案

  1. 连续按两次shift,搜索live,点击Live Templates
  1. 按下图进行操作,配置以下文本内容

自定义生成内容(需要添加其他内容可自行添加):

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd">
        
</beans>
  1. 效果展示,新建一个空xml文件,输入spring按Tab

模板创建成功!


相关推荐
前网易架构师-高司机3 小时前
带标注的扑克牌识别数据集,识别率99.5%,3083张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·数字·扑克牌·纸牌
Y3815326623 小时前
3 种 SERP 数据处理方案对比:流式 / 批处理 / 缓存
java·spring·缓存
Sayuanni%33 小时前
Spring IOC
java·spring·rpc
dkbnull4 小时前
Spring Boot依赖注入方式对比详解
spring boot·spring
正儿八经的少年4 小时前
Spring 事务保证数据一致性
java·数据库·spring
宸津-代码粉碎机5 小时前
SQL 深度精讲|IN 与 NOT IN 用法、底层原理、NULL 致命坑、性能优化(实战干货)
大数据·数据库·sql·spring·搜索引擎·性能优化
叶总没有会5 小时前
3.2 构建AI智能体项目扩展知识
java·数据库·人工智能·spring·ai
执明wa19 小时前
LayoutInflater详解: XML是如何变成View的?
android·xml·开发语言·android studio
我是唐青枫1 天前
Java Spring Security 实战详解:从登录认证到 JWT 权限控制
java·spring
空中湖1 天前
Spring AI 多模态实战:让 AI 看图、听声音、生成图片
人工智能·spring·语音识别