Skip to content

Instantly share code, notes, and snippets.

@blabadi
Created September 24, 2014 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blabadi/3281375e3f4290c5e470 to your computer and use it in GitHub Desktop.
Save blabadi/3281375e3f4290c5e470 to your computer and use it in GitHub Desktop.
package com.blabadi.gradle.rest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.blabadi.gradle.be.Person;
import com.blabadi.gradle.bl.PersonService;
@RestController
public class PersonController {
@Autowired
private PersonService service;
@RequestMapping(value="/person", method = RequestMethod.POST)
public int addPerson(Person p) {
return service.addPerson(p);
}
@RequestMapping(value="/person", method = RequestMethod.PUT)
public boolean update(Person p) {
return false;
}
@RequestMapping(value="/person/{id}", method = RequestMethod.GET)
public Person get(int id) {
return null;
}
}
package com.blabadi.gradle.rest;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInit implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebConfig.class);
ctx.setServletContext(servletContext);
Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
dynamic.addMapping("/");
dynamic.setLoadOnStartup(1);
}
}
package com.blabadi.gradle.rest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import com.blabadi.gradle.bl.BlConfig;
@Configuration
@EnableWebMvc
@Import(BlConfig.class)
@ComponentScan(basePackages = {"com.blabadi.gradle.rest"})
public class WebConfig {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment