springboot版本:1.3.6.RELEASE

package com.pp;
import org.springframework.boot.Sprink h 3 t p y T dgApplication;
import org.springframeworkk ] w.bm T ) =oot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builderE 9 6 + z K 9 H.SpringApplicationX @ E 7 n zBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
@Springd i K \ 7 & j H =BootApp{ \ w 9 ( w W Klication
public class App extenW C ` ) G 8 { : xds SpringBootServletInitializer {
protected SpringApplicationBuiu U @ ilder 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.springfrx k S ~ _ - uamework.weY g 9 xb.bind.annotation.RestA S u ! lControllerR # Q 3 @ X q T $;
import org.springframework.web.context.Contexx 7 8tLoader;
@RestController
public class HomeController {
@RequestMapping("/home")
publi1 5 s cc String home(){
System.oux ^ # 7 Ot.println(ContextLoader.getCurrentWebApplicationContext());X 9 . ; ) d b C c
return "home";
}
}

启动main方法之后(内嵌tomcat8),

System.out.println(ContextLoader.getCurrentWebAppE p V & & 5 8 S qlicationContext());

输出为null

请问,哪里有问题?

回答

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注