0

Grails Version 2.2.4 Jax RS Plugin Version 0.8

I have grails service under Grails-app service folder as below

@Transactional
class HdfsService {

    def write(){

        Configuration configuration = new Configuration();
        FileSystem hdfs = FileSystem.get( new URI( "hdfs://192.168.4.110:9000" ), configuration );
        Path file = new Path("hdfs://192.168.4.110:9000/vinod/table.html");
        if ( hdfs.exists( file )) { hdfs.delete( file, true ); }
        OutputStream os = hdfs.create( file,
                new Progressable() {
                    public void progress() {
                        //println("...bytes written: [ "+bytesWritten+" ]");
                    } });
        BufferedWriter br = new BufferedWriter( new OutputStreamWriter( os, "UTF-8" ) );
        br.write("Hello World");
        br.close();
        hdfs.close();

    }

}

I have a JAX-RS resource in my Grails App as below

class CDSResource implements CDSService {


    def hdfsService;

    @Override
    CDSResponse pushRawData(CDSRequest cdsRequest) {


        println(" Inside CDS Resource")

        // hdfsService.write()

        return null;
    }
}

I find the Grails Service is not getting autowired. Please help

Vinod Jayachandran
  • 3,726
  • 8
  • 51
  • 88

1 Answers1

1

Have you seen Grails 2.x service injection in Groovy/src?

import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes as GA
    def ctx = SCH.servletContext.getAttribute(GA.APPLICATION_CONTEXT)
    def hdfsService = ctx. hdfsService
Community
  • 1
  • 1
swiatows
  • 98
  • 4