springboot版本:1.3.6.RELEASE
package com.pp; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; @SpringBootApplication public class App extends SpringBootServletInitializer { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(App.class); } public static void main(String[] args) { SpringApplication.run(App.class, args); } }
package com.pp; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.ContextLoader; @RestController public class HomeController { @RequestMapping("/home") public String home(){ System.out.println(ContextLoader.getCurrentWebApplicationContext()); return "home"; } }
System.out.println(ContextLoader.getCurrentWebApplicationContext());
输出为null
请问,哪里有问题?