如何将src/main/webapp/WEB-INF/views文件夹移出src/main/webapp/? [英] How do I move my src/main/webapp/WEB-INF/views folder out of src/main/webapp/?

查看:379
本文介绍了如何将src/main/webapp/WEB-INF/views文件夹移出src/main/webapp/?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring MVC src/main/webapp/WEB-INF/views中有一个文件夹,其中包含我的视图模板.我想将其移动到src/main/java/views(或src/main/webapp以外的其他文件夹).如何在Spring MVC中进行配置?

I have a folder in Spring MVC src/main/webapp/WEB-INF/views that contains my view templates. I want to move it to src/main/java/views (or some other folder outside of src/main/webapp). How do I configure that in Spring MVC?

我看到一个文件src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml包含

<beans:property name="prefix" value="/WEB-INF/views/" />

很明显,我可以将其更改为

It's obvious from looking at that that I can change it to

<beans:property name="prefix" value="/views/" />

这会将我的视图放在src/main/webapp/views中,但是我看不到将viewssrc/webapp文件夹中移出的任何方法.

which would put my views in src/main/webapp/views, but I don't see any way to move views out of the src/webapp folder.

换句话说,很显然value="/"等同于src/main/webapp/,所以似乎我仅限于将视图文件夹放在src/main/webapp中.

In other words, it's ultra clear that value="/" is equivalent to src/main/webapp/, so it seems like I'm limited to putting my view folder inside src/main/webapp.

实际上,如何将我的视图文件夹设置为在src/main/webapp之外(例如在src/main/foobar中!)?无论我在Google/Bing上搜索什么,我都找不到任何东西.

How in the world do I set my view folder to be outside of src/main/webapp, for example in src/main/foobar!?! No matter what I search on Google/Bing I can't find anything.

我试图使用/../来实现它:

<beans:property name="prefix" value="/../java/edu/csus/csc191/views/" />

但这会导致显示错误

严重:Servlet [appServlet]的Servlet.service()与 路径[/hp-dsat]引发异常[请求处理失败;嵌套的 异常是org.thymeleaf.exceptions.TemplateInputException:错误 解决模板"v2_upload",模板可能不存在或可能不存在 可以由任何已配置的模板解析器使用root访问 原因

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/hp-dsat] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "v2_upload", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

所述模板确实存在于src/main/webapp/../java/views中,它等效于src/main/java/views

The said template does exist in src/main/webapp/../java/views which is equivalent to src/main/java/views

推荐答案

通常在构建应用程序时会警告它会在src/main/webapp中查找组件,您可以使用maven自定义项目结构来更改它.

Normally on application build to war it will look for components in src/main/webapp, You can change this using maven custom project structure.

如何配置自定义Maven项目结构

最好将视图组件保留在WEB-INF中,因为它不能公开访问.

It is better to keep the view components in WEB-INF because it is not publicly accessible.

这篇关于如何将src/main/webapp/WEB-INF/views文件夹移出src/main/webapp/?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆