Created
October 30, 2014 20:09
-
-
Save 2garryn/173e85b4e71f834d609b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package HelloPackage; | |
import org.springframework.boot.*; | |
import org.springframework.boot.autoconfigure.*; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.stereotype.*; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.Arrays; | |
// @RestController | |
@Configuration | |
@ComponentScan | |
@EnableAutoConfiguration | |
public class Hello { | |
public static void main(String[] args) throws Exception { | |
ApplicationContext ctx = SpringApplication.run(Hello.class, args); | |
System.out.println("Let's inspect the beans provided by Spring Boot:"); | |
String[] beanNames = ctx.getBeanDefinitionNames(); | |
Arrays.sort(beanNames); | |
for (String beanName : beanNames) { | |
System.out.println(beanName); | |
} | |
// SpringApplication.run(MyController.class, args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package HelloPackage; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import org.springframework.web.bind.annotation.ResponseBody; | |
import org.springframework.web.bind.annotation.RestController; | |
import javax.servlet.http.HttpServletResponse; | |
/** | |
* Created by garry on 10/31/14. | |
*/ | |
@Controller | |
@RequestMapping("/api") | |
public class MyController { | |
public MyController() { | |
System.out.println("Initialization of my controller"); | |
}; | |
@RequestMapping(value="login", method = RequestMethod.GET, headers="Accept=application/json") | |
public @ResponseBody Person get(HttpServletResponse res){ | |
Person person = new Person(); | |
person.setId(1); | |
person.setName("hmk"); | |
return person; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package HelloPackage; | |
import java.io.Serializable; | |
/** | |
* Created by garry on 10/31/14. | |
*/ | |
public class Person implements Serializable { | |
private static final long serialVersionUID = 1L; | |
private int Id; | |
private String Name; | |
public Person(){ | |
System.out.println("Initialization of Person"); | |
}; | |
public void setId(int Id){ | |
this.Id = Id; | |
}; | |
public void setName(String Name){ | |
this.Name = Name; | |
}; | |
public int getId() { | |
return Id; | |
}; | |
public String getName(){ | |
return Name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment