Skip to content

Instantly share code, notes, and snippets.

@2garryn
Created October 30, 2014 20:09
Show Gist options
  • Save 2garryn/173e85b4e71f834d609b to your computer and use it in GitHub Desktop.
Save 2garryn/173e85b4e71f834d609b to your computer and use it in GitHub Desktop.
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);
}
}
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;
}
}
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