/java/

Simple way to start with JAX-RS

2014-04-08 23:11:11

GIT:https://github.com/szalek/jee-jaxrs-inject

<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>

<project http:="" maven-4.0.0.xsd&quot;="" maven.apache.org="" xmlns='"http://maven.apache.org/POM/4.0.0"' xmlns:xsi='"http://www.w3.org/2001/XMLSchema-instance"' xsd="" xsi:schemalocation='"http://maven.apache.org/POM/4.0.0'>
<modelversion>4.0.0</modelversion>
<build>
<finalname>app</finalname>
</build>
<groupid>pl.btbw.jeetest2</groupid>
<artifactid>jeetest2</artifactid>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupid>javax</groupid>
<artifactid>javaee-api</artifactid>
<version>6.0</version>
</dependency>
</dependencies>
</project>

package pl.btbw.core;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/")
public class MyApplication extends Application {
}
package pl.btbw.web.controller;

import pl.btbw.web.service.HelloService;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

@Path("/hello")
public class HelloController {

    @Inject
    private HelloService helloService;

    @GET
    public String doHello() {
        return helloService.getT();
    }
}
package pl.btbw.web.service;

import javax.ejb.Stateless;

@Stateless
public class HelloService {

    public String getT() {
        return "Hello lorem ipsum !";
    }

}
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>

<beans beans_1_0.xsd&quot;="" http:="" java.sun.com="" javaee="" ns="" xml="" xmlns='"http://java.sun.com/xml/ns/javaee"' xmlns:xsi='"http://www.w3.org/2001/XMLSchema-instance"' xsi:schemalocation='"http://java.sun.com/xml/ns/javaee'>
</beans>