SpringBoot如何写xml

众所周知,在springboot中是不需要写xml配置的,但是理论上技术是可行的,今天我们就来试一试
第一步:
就拿hello来试.首先创建一个helloController并且不带注解

public class Hello {
    public String sayHello(){

        return "hello";
    }
}

第二步
创建一本beans.xml,然后把Hello注入给容器





    

第三步
将beans.xml生效,只需要写一个配置类

@Configuration
@ImportResource(locations = "classpath:beans.xml")
public class WebMVCConfig {
}

并且在@ImportResource注解中添加xml文件的地址

好了大功告成啦!

你可能感兴趣的:(SpringBoot如何写xml)