Spring boot maven management-HelloWorld

Source: Internet
Author: User

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!








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.