我有一个新的angular2项目,它是使用快速入门中描述的标准文件结构构建的。我正在尝试构建一个API网关并使用spring-boot host我的应用程序,但是我无法配置启动以在我的项目中使用/ dist目录创建生成的源。项目结构如下:
structure(list(`2001` = c(349.315750645518, 217.47436370343,
5.17963850977499, 126.661748432313, 57, 39), `2002` = c(703.26693877551,
429.92, 9.32897959183673, 264.017959183673, 161, 108), `2003` = c(314.897774687065,
193.792420027816, 4.08936022253129, 117.015994436718, 54, 37),
`2004` = c(305.988451086957, 190.680027173913, 3.87839673913043,
111.430027173913, 55, 38), `2005` = c(118.528015659408, 74.3175923660387,
1.50942011255199, 42.7010031808172, 10, 8), `2006` = c(120.531992244304,
73.8279205041202, 1.54362578768783, 45.1604459524964, 10,
8), `2007` = c(113.973899988451, 69.7619817530893, 1.44693382607691,
42.7649844092851, 10, 8), `2008` = c(110.676242590059, 67.3693570451436,
1.36285909712722, 41.9440264477884, 9, 7), `2009` = c(101.965558714192,
63.1446534003936, 1.22982724688388, 37.5910780669145, 9,
7), `2010` = c(93.9744360902256, 59.8894736842105, 1.14199785177229,
32.9429645542427, 9, 7), `2011` = c(91.8911316298046, 58.5660296328108,
1.15675327464033, 32.1683487223534, 9, 7), `2012` = c(91.2302181013592,
58.598356337583, 1.16773785691708, 31.4641239068591, 8, 6
), `2013` = c(87.1390443392165, 55.0509040034438, 1.10277658200603,
30.9853637537667, 8, 6), `2014` = c(85.7812132234942, 56.0456831068792,
1.09725045469134, 28.6382796619236, 8, 6), `2015` = c(88.331452900479,
58.526237360298, 1.22362959020756, 28.5815859499734, 8, 6
)), .Names = c("2001", "2002", "2003", "2004", "2005", "2006",
"2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014",
"2015"), row.names = c("AllDataMeanByYear", "AllDataMeanAggAssault",
"AllDataMeanMurderManSlaughter", "AllDataMeanRobbery", "AllDataMedianByYear",
"AllDataMedianAggAssault"), class = "data.frame")
All Code:
## Total
lwdata$total <- lwdata$murdermanslaughter + lwdata$Robbery + lwdata$Aggravated_assault
## Data Calculations Top 15
top15 <- lwdata[lwdata$total >= lwdata$total[order(lwdata$Year, lwdata$total, decreasing=TRUE)][15] , ]
## Top 15 Means
Top15MeanByYear <- tapply(top15$total,top15$Year,mean)
Top15MeanAggAssault <- tapply(top15$Aggravated_assault,top15$Year,mean)
Top15MeanMurderManSlaughter <- tapply(top15$murdermanslaughter,top15$Year,mean)
Top15MeanRob <- tapply(top15$Robbery,top15$Year,mean)
## All Data Means
AllDataMeanByYear <- tapply(lwdata$total,lwdata$Year,mean)
AllDataMeanAggAssault <- tapply(lwdata$Aggravated_assault,lwdata$Year,mean)
AllDataMeanMurderManSlaughter <- tapply(lwdata$murdermanslaughter,lwdata$Year,mean)
AllDataMeanRobbery <- tapply(lwdata$Robbery,lwdata$Year,mean)
## Top 15 Medians
Top15MedianByYear <- tapply(top15$total,top15$Year,median)
Top15MedianAggAssault <- tapply(top15$Aggravated_assault,top15$Year,median)
Top15MedianMurderManSlaughter <- tapply(top15$murdermanslaughter,top15$Year,median)
Top15MedianRob <- tapply(top15$Robbery,top15$Year,median)
## All Data Medians
AllDataMedianByYear <- tapply(lwdata$total,lwdata$Year,median)
AllDataMedianAggAssault <- tapply(lwdata$Aggravated_assault,lwdata$Year,median)
AllDataMedianMurderManSlaughter <- tapply(lwdata$murdermanslaughter,lwdata$Year,median)
AllDataMedianRobbery <- tapply(lwdata$Robbery,lwdata$Year,median)
## Rounding Data To Two Decimal Points
Top15MeanByYear <- round(Top15MeanByYear,digits=2)
Top15MeanAggAssault <- round(Top15MeanAggAssault,digits=2)
Top15MeanMurderManSlaughter <- round(Top15MeanMurderManSlaughter,digits=2)
Top15MeanRob <- round(Top15MeanRob,digits=2)
AllDataMeanByYear <- round(AllDataMeanByYear,digits=2)
AllDataMeanAggAssault <- round(AllDataMeanAggAssault,digits=2)
AllDataMeanAggAssault <- round(AllDataMeanAggAssault,digits=2)
AllDataMeanRobbery <- round(AllDataMeanRobbery,digits=2)
Top15MedianByYear <- round(Top15MedianByYear,digits=2)
Top15MedianAggAssault <- round(Top15MedianAggAssault,digits=2)
Top15MedianMurderManSlaughter <- round(Top15MedianMurderManSlaughter,digits=2)
Top15MedianRob <- round(Top15MedianRob,digits=2)
AllDataMedianByYear <- round(AllDataMedianByYear,digits=2)
AllDataMedianAggAssault <- round(AllDataMedianAggAssault,digits=2)
AllDataMedianMurderManSlaughter <- round(AllDataMedianMurderManSlaughter,digits=2)
AllDataMedianRobbery <- round(AllDataMedianRobbery,digits=2)
## Summaries
AllDataSummary <- rbind(AllDataMeanByYear, AllDataMeanAggAssault, AllDataMeanMurderManSlaughter, AllDataMeanRobbery, AllDataMedianByYear, AllDataMedianAggAssault, AllDataMedianMurderManSlaughter, AllDataMedianRobbery)
Top15Summary <- rbind(Top15MeanByYear, Top15MeanAggAssault, Top15MeanMurderManSlaughter, Top15MeanRob,Top15MedianByYear,Top15MedianAggAssault,Top15MedianMurderManSlaughter,Top15MedianRob)
Top15andAllDatasummary <- rbind(AllDataSummary,Top15Summary)
## Class of New Items
class(AllDataSummary)
class(Top15Summary)
class(top15andAllDatasummary)
## Converting Matrices to Data Frames
AllDataSummary.df <- as.data.frame(AllDataSummary)
Top15Summary.df <- as.data.frame(Top15Summary)
Top15andAllDatasummary.df <- as.data.frame(Top15andAllDatasummary)
## Checking of New Classes
class(AllDataSummary.df)
class(Top15Summary.df)
class(Top15andAllDatasummary.df)
## Verifications for Names of New Components
colnames(Top15andAllDatasummary.df)
rownames(Top15andAllDatasummary.df)
## New Components
years <- colnames(Top15andAllDatasummary.df)
calculations <- colnames(Top15andAllDatasummary.df)
## Chicago
Chicago <- top15[which(top15$City=="Chicago"), ]
## Basic Plots
plot(y=Chicago$total, x=Chicago$Year, type="l", xlab = "Year", ylab = "Total Violent Crime (minus rape)", main="Chicago-Specific Data", col="blue")
## Data Types for Chicago
str(Chicago)
我想使用default / dist目录,这样我仍然可以使用npm / webpack在UI上进行持续开发。
我尝试像这样配置静态资源目录:
project
|--dist
|--node_modules
|--src
| |--app
| |--assets
| |--main
| | |--java
| | |--resources
| | | |--config
| | |--webapp
| | | |--WEB-INF
但这似乎没有用。
我创建了一个资源处理程序,直接指向dist目录:
spring.resources.staticLocations: /dist
这解决了问题的一部分,但现在我的根URL('/')不再映射到index.html。
有没有更简单/更好的方法来配置spring-boot来查找/ dist项目目录?我的项目结构应该改变吗?我真的希望让所有这些部分干净利落地工作。
答案 0 :(得分:2)
Spring Boot会自动添加静态Web资源 位于以下任何目录中:
/META-INF/resources/
/resources/
/static/
/public/
文件夹相对于src / main / resources
如果您将index.html放在下面,那么spring可以为您的文件提供服务 没有任何配置。
src/main/resources/META-INF/resources/index.html
src/main/resources/resources/index.html
src/main/resources/static/index.html
src/main/resources/public/index.html
答案 1 :(得分:1)
我接受了@chrylis的建议,并将webpack构建的目标目录指向build / dist(使用Gradle)。
我避免将生成的源文件放在/resources/**
中,因为最终这会被内置到.war中并部署到企业应用程序服务器 - 我不想在我的内容中包含很多包含/排除逻辑建立以支持这一点。另外,构建目录对于生成的.js源来说似乎更合乎逻辑。
我的项目结构现在看起来像这样:
project
|--build
| |--dist
| |--...
|--node_modules
|--src
| |--app
| |--assets
| |--main
| | |--java
| | |--resources
| | | |--config
| | |--webapp
| | | |--WEB-INF
我删除了WebMvcConfigurerAdapter,并将静态资源配置为指向构建中的dist目录:
spring.resources.static-locations: "file:./build/dist/"
我现在能够运行Webpack,Spring-Boot或部署到我的应用服务器,具有相同的源和极少的配置开销。