title: Spring annotation gives null value in my Spring MVC when I create JAX-RS Web service
body: <p>I added JAX-RS Web service for my project .I want to get XML file. It works fine when I hard cord something on return statement and it works fine. But I want to get data from my database. I use </p>
  
  <pre><code> @Autowired
   private ProductServices productServices;
  </code></pre>
  
  <p>for call Spring Service class... For other normal controllers this @Autowired working fine. In JAX-RS it doesn't works.
  <a href="https://i.stack.imgur.com/Mr84K.jpg" rel="nofollow noreferrer">JAX-RS gives null value like this</a></p>
  
  <p>I want to call this service for get data to my method. How can I do that..</p>
  
  <p>This is my Model.</p>
  
  <pre><code>@Entity
  @Table(name = "products")
  @XmlRootElement
  public class Product {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "product_id")
      private long productId;
  
      @NotNull
      private String serialNo;
      @NotNull
      private int slsiUnit;
      @NotNull
      private String itemDesc;
      @NotNull
      private int slsNo;
      @NotNull
      private String hsCode;
  
      @NotNull
      private String userIDandTime;
  
      @NotNull
      private String recentUpdateBy;
  
      public long getProductId() {
          return productId;
      }
  
      public void setProductId(long productId) {
          this.productId = productId;
      }
  
      public String getSerialNo() {
          return serialNo;
      }
  
      public void setSerialNo(String serialNo) {
          this.serialNo = serialNo;
      }
  
      public int getSlsiUnit() {
          return slsiUnit;
      }
  
      public void setSlsiUnit(int slsiUnit) {
          this.slsiUnit = slsiUnit;
      }
  
      public String getItemDesc() {
          return itemDesc;
      }
  
      public void setItemDesc(String itemDesc) {
          this.itemDesc = itemDesc;
      }
  
      public int getSlsNo() {
          return slsNo;
      }
  
      public void setSlsNo(int slsNo) {
          this.slsNo = slsNo;
      }
  
      public String getHsCode() {
          return hsCode;
      }
  
      public void setHsCode(String hsCode) {
          this.hsCode = hsCode;
      }
  
      public String getUserIDandTime() {
          return userIDandTime;
      }
  
      public void setUserIDandTime(String userIDandTime) {
          this.userIDandTime = userIDandTime;
      }
  
      public String getRecentUpdateBy() {
          return recentUpdateBy;
      }
  
      public void setRecentUpdateBy(String recentUpdateBy) {
          this.recentUpdateBy = recentUpdateBy;
      }
  }
  </code></pre>
  
  <p>This is my Repository.</p>
  
  <pre><code>public interface ProductRepository extends CrudRepository&lt;Product, Long&gt; {
  
      @Override
      Product save(Product product);
  
      @Override
      Product findOne(Long productId);
  
      @Override
      List&lt;Product&gt; findAll();
  
      @Override
      void delete(Long productId);
  }
  </code></pre>
  
  <p>This is my Services class</p>
  
  <pre><code>@Service
  public class ProductServices {
  
      private static final Logger serviceLogger = LogManager.getLogger(ProductServices.class);
  
      @Autowired
      private ProductRepository productRepository;
  
      public List&lt;Product&gt; getProductList() {
          return productRepository.findAll();
      }
  
      public Product getProductById(long productId) {
          return productRepository.findOne(productId);
      }
  }
  </code></pre>
  
  <p>This is my JAX-RS Web Service class</p>
  
  <pre><code>@Path("release")
  public class GenericResource {
  
      @Context
      private UriInfo context;
  
      @Autowired
      private ProductServices productServices;
  
      public GenericResource() {
      }
  
      @GET
      @Produces(MediaType.APPLICATION_XML)
      public List&lt;Product&gt; getXml() {
          List&lt;Product&gt; a = productServices.getProductList();
          return a;
      }
  }
  
  This is the MessageBodyWriter
  
  @Provider
  @Produces(MediaType.APPLICATION_XML)
  public class restConverter implements MessageBodyWriter&lt;List&lt;Product&gt;&gt; {
  
      @Override
      public boolean isWriteable(Class&lt;?&gt; type, Type genericType, Annotation[] annotations, MediaType mediaType) {
          return Product.class.isAssignableFrom(type);
      }
  
      @Override
      public long getSize(List&lt;Product&gt; t, Class&lt;?&gt; type, Type genericType, Annotation[] annotations, MediaType mediaType) {
          return -1;
      }
  
      @Override
      public void writeTo(List&lt;Product&gt; t, Class&lt;?&gt; type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap&lt;String, Object&gt; httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
          out.write(t.toString().getBytes());
      }
  
  }
  </code></pre>
  
  <p>This is a extend class for JSX-RS</p>
  
  <pre><code>@ApplicationPath("TransferPermit/Slsi_Customs/restAPI")
  public class restConfig extends Application{
  
  }
  </code></pre>
  
  <p>This is my pom.xml</p>
  
  <pre><code>&lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!--handle servlet--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!--&lt;Email Dependency&gt;--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
              &lt;version&gt;1.4.3.RELEASE&lt;/version&gt;      
          &lt;/dependency&gt;
  
  
          &lt;!--Add mysql dependency--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;6.0.3&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
          &lt;!--jasper--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.jasperreports&lt;/groupId&gt;
              &lt;artifactId&gt;jasperreports&lt;/artifactId&gt;
              &lt;version&gt;3.7.6&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.bundles&lt;/groupId&gt;
              &lt;artifactId&gt;jaxrs-ri&lt;/artifactId&gt;
              &lt;version&gt;2.13&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.10&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.mail&lt;/groupId&gt;
              &lt;artifactId&gt;javax.mail-api&lt;/artifactId&gt;
              &lt;version&gt;1.5.5&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
              &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
              &lt;version&gt;2.0.1&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>Special : This cord works fine. But in Web service class productServices auto-wired dependency not working. What is the error :</strong> </p>
  
  <pre><code>@RequestMapping(value = "/ViewProduct", produces = {MediaType.APPLICATION_JSON_VALUE}, method = RequestMethod.GET)
          @JsonIgnore
          public ResponseEntity&lt;List&lt;Product&gt;&gt; listAllProducts() {
              List&lt;Product&gt; viewProducts = productServices.getProductList();
              if (viewProducts.isEmpty()) {
                  return new ResponseEntity&lt;List&lt;Product&gt;&gt;(HttpStatus.NO_CONTENT);
              }
              System.out.println("entity " + new ResponseEntity&lt;List&lt;Product&gt;&gt;(HttpStatus.NO_CONTENT));
              return new ResponseEntity&lt;List&lt;Product&gt;&gt;(viewProducts, HttpStatus.OK);
      }
  </code></pre>
  
  <p>What is the error in my cord. How can I call data from database</p>
  
  <p>Please help me someone for return XML... </p>