Spring启动,View的可能原因无法解决问题(Spring boot, possible causes of View cannot be resolved issue)
如果Spring Boot无法解析具有特定名称的视图,可能会出现什么问题?
我以前开发过很多Spring Boot应用程序,但从未遇到过这个问题。
我有以下文件夹结构:
/src/main/java /src/main/resources/config /src/main/resources/static /src/main/resources/static/partials /src/main/resources/static/resources
图片:
/src/main/resources/static/resources
文件夹没有resources
名称的问题。 我尝试重命名它并没有解决问题。我正在使用Maven,我有一个有多个子项目的父项目。
其余api的模块包含许多配置类,包括安全性配置。
一切正常,应用程序可以正常启动,但是当我尝试添加静态内容时遇到了这个问题。
从下面的示例( 示例 )中我们可以看到Spring Boot应该自动将
src/main/resources/static/index.html
映射到根路径,但这不会发生在我的应用程序中。 从日志中我可以看到Spring没有找到/
映射。我能够正常运行该示例,但在我的应用程序中它不起作用。 因为Spring没有自动映射我创建了应该返回视图的
WelcomeController
:@Controller public class WelcomeRestController { @RequestMapping("/") public String welcome() { return "index.html"; } }
在我这样做之后,找到了映射,但Spring报告它无法解析名为
index.html
视图,即使它存在。我尝试将静态内容添加到
src/main/webapp/static
文件夹,即使它不推荐也没有用,同样的问题,无法解析视图。我也尝试配置使用
@Configuration public class WebMvcConfiguration extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index.html"); } }
同样,视图无法解决。
我的应用程序的起点:
@Import(MyRestServiceConfiguration.class) @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(final String[] args) { SpringApplication.run(Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } }
我正在使用嵌入式Tomcat。
是否可能安全配置或除
WebMvcConfigurerAdapter
之外的某些其他配置对视图有影响?我试图解决这个问题几个小时,但我找不到解决方案。 任何帮助,将不胜感激。
编辑:
我不是使用Maven构建应用程序,只是将
Application.java
作为Java应用程序运行,因此Maven应该不是问题。编辑:index.html的内容:
<!DOCTYPE html> <html > <head lang="en"> </head> <body> <div>Hello</div> </body> </html>
What could be the problem if Spring Boot cannot resolve view with specific name?
I have developed many Spring Boot applications before and have never encountered this problem.
I have following folder structure:
/src/main/java /src/main/resources/config /src/main/resources/static /src/main/resources/static/partials /src/main/resources/static/resources
Image:
/src/main/resources/static/resources
folder is not making problems for havingresources
name. I tried renaming it and it didn't solve problem.I am using Maven and I have parent project which has multiple children projects.
Module for the rest api contains many configuration classes, including configurations for security.
Everything is working as it should, application can be started without errors, but when I tried to add static content I encountered this problem.
From the following example (example) we can see that Spring Boot should automatically maps
src/main/resources/static/index.html
to the root path, but that is not happening in my application. From the log I can see that Spring didn't find mapping for/
.I am able to run that example normally, but in my application it is not working. Because Spring didn't map automatically I created
WelcomeController
which should return view:@Controller public class WelcomeRestController { @RequestMapping("/") public String welcome() { return "index.html"; } }
After I did that, mapping is found, but Spring reports that it couldn't resolve view with name
index.html
even if it exists.I tried adding static content to
src/main/webapp/static
folder even if it is not recommended and it also didn't work, same problem, cannot resolve view.I also tried to configure using
@Configuration public class WebMvcConfiguration extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index.html"); } }
Again, view cannot be resolved.
My application's start point:
@Import(MyRestServiceConfiguration.class) @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(final String[] args) { SpringApplication.run(Application.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); } }
I am using embedded Tomcat.
Is it possible that security configurations or some other configurations except
WebMvcConfigurerAdapter
are having influence on views?I am trying to resolve this issue for hours but I can't find soulution. Any help would be appreciated.
EDIT:
I am not building application using Maven, just running
Application.java
as Java Application, so Maven should not be a problem.EDIT: Content of index.html:
<!DOCTYPE html> <html > <head lang="en"> </head> <body> <div>Hello</div> </body> </html>
原文:https://stackoverflow.com/questions/38120062
最满意答案
for stats in ['passes','tackles','shots','saves']: cc = np.corrcoef(players['minutes'], players[stats])[1,0] print cc
for stats in ['passes','tackles','shots','saves']: cc = np.corrcoef(players['minutes'], players[stats])[1,0] print cc
相关问答
更多-
您需要为DataFrame构造函数指定data , index和columns ,如: >>> pd.DataFrame(data=data[1:,1:], # values ... index=data[1:,0], # 1st column as index ... columns=data[0,1:]) # 1st row as the column names 编辑 :如在@joris注释中,您可能需要将以上更改为np.int_(d ...
-
如果我们在谈论数组 : import numpy as np a = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6], dtype=np.float) print 1 / a[a <= 0.5] * (-1) 但是,这只会返回小于0.5的值。 或者使用np.where : import numpy as np a = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6], dtype=np.float) print np.where(a < 0.5 ...
-
它看起来像一个3D阵列。 您可以将其第一个元素传递给DataFrame构造函数: pd.DataFrame(Y_test[0], columns=['y_test']) Out: y_test 0 71010592.0 1 91873632.0 2 83556280.0 3 71659064.0 4 82806096.0 5 67704200.0 6 70719536.0 7 104754616.0 8 72742040.0 9 ...
-
使用NumPy broadcasting一种方法 - # Extract index and column as int arrays indx = df.index.values.astype(int) cols = df.columns.values.astype(int) # Perform elementwise subtracttion between all elems of indx against all cols a = np.abs(indx[:,None] - cols) df_ou ...
-
使用标头和dtypes将pandas数据帧转换为numpy数组(Converting pandas dataframe to numpy array with headers and dtypes)[2022-09-07]
使用df.to_records()将数据帧转换为结构化数组。 您可以传递index=False以从结果中删除索引。 import numpy as np df = pd.DataFrame(np.random.rand(10,3),columns=['Acol','Ccol','Bcol']) res = df.to_records(index=False) # rec.array([(0.12448699852020828, 0.7621451848466592, 0.095852994383143 ... -
对于具有numpy / pandas的循环(迭代列标题)(For loops with numpy/pandas (iterating over column headers))[2022-08-08]
for stats in ['passes','tackles','shots','saves']: cc = np.corrcoef(players['minutes'], players[stats])[1,0] print cc for stats in ['passes','tackles','shots','saves']: cc = np.corrcoef(players['minutes'], players[stats])[1,0] print cc -
PyTables是用于管理分层数据集的软件包。 它旨在为您解决这个问题。 PyTables is a package for managing hierarchical datasets. It is designed to solve this problem for you.
-
将常量numpy数组值分配给pandas dataframe列(Assign constant numpy array value to pandas dataframe column)[2022-07-06]
IIUC,您的“新”列将包含数组,因此它必须是对象类型列。 初始化它的最简单方法是: my_df = pd.DataFrame({'col_1': [1,2,3], 'col_2': [4,5,6]}) my_df['new']=None 然后,您可以根据需要填写它。 例如 : for index,(a,b,_) in my_df.iterrows(): my_df.loc[index,'new']=np.arange(a,b) # # col_1 col_2 n ... -
在numpy数组中迭代(Iterating in numpy arrays)[2022-03-17]
if f > 0: ,则该行抛出ValueError 。 你有f作为一个数字数组,你问它是正数: f > 0给你一个布尔值数组。 if语句需要一个布尔表达式,但是你不能将布尔数组强制转换为单个布尔值。 正如异常消息所述,要使用您拥有的代码,您需要将f > 0更改为(f > 0).any()或(f > 0).all() 。 你的问题听起来像你要做的是计算index为True ,其中f在同一位置是正的(也就是说, if f[i+1] > 0: ,你实际意味着什么if f[i+1] > 0: 。 如果是这种情况, ... -
迭代numpy矩阵列(iterating over numpy matrix columns)[2023-10-28]
最好使用2d np.array而不是矩阵。 import numpy as np data = np.array([[1, 2, 0], [0, 0, 1], [0, 2, 4]], dtype='float') data[data == 0] = np.nan # replace all zeroes with `nan`'s to skip them # [[ 1. 2. nan] # [ nan nan 1.] # [ nan 2. 4.]] np.nanmean(data, a ...