Created
September 24, 2014 20:11
-
-
Save blabadi/3281375e3f4290c5e470 to your computer and use it in GitHub Desktop.
This file contains 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 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; | |
} | |
} |
This file contains 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 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); | |
} | |
} |
This file contains 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 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