我正在尝试测试使用src / main / webapp / folder下的文件的服务方法,但是由于任何原因似乎没有访问权限或某些原因,它无法正常工作,获取文件的代码是以下:
def file = grailsApplication.parentContext.getResource("folder/file.txt").file
,错误是:
ServletContext resource [/folder/file.txt] cannot be resolved to absolute file path - web application archive not expanded?
有什么想法吗? 它不是grailsApplication ininction或get resource方法,我认为服务在测试框架使用该服务时无法访问该路径。
答案 0 :(得分:0)
查看位于https://github.com/jeffbrown/davidpadillaservice的项目。
https://github.com/jeffbrown/davidpadillaservice/blob/master/src/main/resources/folder/file.txt
#include <gtk/gtk.h>
static gboolean button_press_callback (GtkWidget *event_box, GdkEventButton *event, gpointer data)
{
g_print ("Event box clicked at coordinates %f,%f\n",
event->x, event->y);
/* Returning TRUE means we handled the event, so the signal
* emission should be stopped (don't call any further
* callbacks that may be connected). Return FALSE
* to continue invoking callbacks.
*/
return TRUE;
}
static GtkWidget*
create_image (void)
{
GtkWidget *image;
GtkWidget *event_box;
image = gtk_image_new_from_file ("image.png");
}
int main(int argc, char const *argv[])
{
create_image();
return 0;
}
line number one
line number two
line number three
package davidpadillaservice
import org.springframework.beans.factory.annotation.Value
import org.springframework.core.io.Resource
class SomeResourceService {
@Value("classpath:folder/file.txt")
Resource fileResource
String getFirstLine() {
getLine(0)
}
String getSecondLine() {
getLine(1)
}
protected String getLine(int index) {
fileResource.file.readLines().get(index)
}
}
我希望有帮助。