After the configuration file is configured, you can write the first example!
@ Controller
@ EnableAutoConfiguration ()
Public class SampleController
{
Private Hello;
@ Autowired
Public SampleController (Hello hello)
{
This. hello = hello;
}
@ RequestMapping ("/")
@ ResponseBody
String home (String type)
{
System. out. println ("login:" + hello );
Return "Hello World ";
}
Public static void main (String [] args) throws Exception
{
SpringApplication app = new SpringApplication (SampleController. class );
App. setWebEnvironment (true );
App. setShowBanner (false );
SetSet = new HashSet();
Set. add ("classpath: applicationContext. xml ");
App. setSources (set );
App. run (args );
}
}
Right-click the java application and enter: localhost: 8080/in the browser/
Display
It indicates that the configuration is successful, and the following is a simple analysis of the program: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> The url of the request. The default value is the method name.
@ ResponseBody: return data in json format
SetSet = new HashSet();
Set. add ("classpath: applicationContext. xml ");
Customize the location of the spring configuration file, because springboot uses the default location, which can be modified according to the actual situation!