Skip to content

Instantly share code, notes, and snippets.

@justinwyer
Created July 8, 2012 12:33
Show Gist options
  • Save justinwyer/3070769 to your computer and use it in GitHub Desktop.
Save justinwyer/3070769 to your computer and use it in GitHub Desktop.
Java EE 6 Web Profile without the app server. Part 2.
@Path("/deed")
@RequestScoped
public class DeedService
{
@Inject
private GoodStuff goodStuff;
@POST
@Path("/good")
public Response doGoodDeed()
{
goodStuff.doSomethingGood();
try
{
return Response.created(new URI("http://www.lifeasageek.com")).build();
}
catch (URISyntaxException ex)
{
return Response.serverError().build();
}
}
}
public class RestConfig extends Application
{
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> classes = new HashSet<>();
classes.add(DeedService.class);
return classes;
}
}
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.lifeasageek.goodstuffexample.RestConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment