众所周知,在springboot中是不需要写xml配置的,但是理论上技术是可行的,今天我们就来试一试
第一步:
就拿hello来试.首先创建一个helloController并且不带注解
复制代码
1
2
3
4
5
6public class Hello { public String sayHello(){ return "hello"; } }
第二步
创建一本beans.xml,然后把Hello注入给容器
复制代码
1
2
3
4
5
6
7<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="包地址" id="hello"></bean> </beans>
第三步
将beans.xml生效,只需要写一个配置类
复制代码
1
2
3
4
5@Configuration @ImportResource(locations = "classpath:beans.xml") public class WebMVCConfig { }
并且在@ImportResource注解中添加xml文件的地址
好了大功告成啦!
最后
以上就是甜蜜白猫最近收集整理的关于SpringBoot如何写xml的全部内容,更多相关SpringBoot如何写xml内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复