Grails 服务未在 jaxrs 资源中自动装配 class

Grails Service not autowired inside jaxrs resource class

Grails 版本 2.2.4 Jax RS 插件版本 0.8

我在 Grails-app 服务文件夹下有 grails 服务,如下所示

@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();

    }

}

我的 Grails 应用程序中有一个 JAX-RS 资源,如下所示

class CDSResource implements CDSService {


    def hdfsService;

    @Override
    CDSResponse pushRawData(CDSRequest cdsRequest) {


        println(" Inside CDS Resource")

        // hdfsService.write()

        return null;
    }
}

我发现 Grails 服务没有自动装配。请帮助

你见过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