2015-09-29 2 views
0

Grails Version 2.2.4 Jax RS Plugin Version 0,8Grails служба не autowired внутри класса jaxrs ресурсов

У меня есть Grails службу по служебной папке 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(); 

    } 

} 

У меня есть Ресурс JAX-RS в моем приложении Grails, как показано ниже

class CDSResource implements CDSService { 


    def hdfsService; 

    @Override 
    CDSResponse pushRawData(CDSRequest cdsRequest) { 


     println(" Inside CDS Resource") 

     // hdfsService.write() 

     return null; 
    } 
} 

Я нахожу, что служба Grails не проходит автоматически. Пожалуйста, помогите

ответ

1

Вы видели 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 
+0

с его помощью для файлов под Grailsapp/resources files? –

Смежные вопросы