使用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

模板创建成功!


相关推荐
用户83071968408212 小时前
spring ai alibaba + nacos +mcp 实现mcp服务负载均衡调用实战
spring boot·spring·mcp
NE_STOP4 天前
springMVC-HTTP消息转换器与文件上传、下载、异常处理
spring
JavaGuide4 天前
Claude Opus 4.6 真的用不起了!我换成了国产 M2.5,实测真香!!
java·spring·ai·claude code
玹外之音5 天前
Spring AI MCP 实战:将你的服务升级为 AI 可调用的智能工具
spring·ai编程
来一斤小鲜肉5 天前
Spring AI入门:第一个AI应用跑起来
spring·ai编程
NE_STOP5 天前
springMVC-常见视图组件与RESTFul编程风格
spring
what丶k5 天前
Spring AI 多模态开发全解析:从入门到企业级落地
后端·spring·ai编程
NE_STOP5 天前
springMVC-获取前端请求的数据与三个作用域
spring
莫寒清5 天前
Spring MVC:@PathVariable 注解详解
java·spring·mvc