npmでビルドした結果のWebページをSpring経由で提供したいと思いますが、すべて正常に動作しますが、main.xxxx.yyy実際の接尾辞が何であるか(css、js、html)ファイル名にドットを含む静的コンテンツを提供するスプリング
ディレクトリツリーは、そのようなものです:私はいくつかのファイルを手動で名前を変更しましたし、それが動作する問題をデバッグするに
@SpringBootApplication
public class Application {
private static Logger log=Logger.getLogger(Application.class.getName());
@Bean
WebMvcConfigurer configurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addResourceHandlers (ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/static/*").
addResourceLocations("classpath:/static/");
}
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
super.configurePathMatch(configurer);
configurer.setUseSuffixPatternMatch(false);
}
};
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
ので、私はしました:
src/main/resource/resource
index.html
asset-manifest.json
favicon.ico
manifest.json
service-worker.js
static
css
main.fc656101.css
main.fc656101.css.map
js
main.91794276.js
main.91794276.js.map
media
banner.bdcf92f4.jpg
fontawesome-webfont.912ec66d.svg
...
これは、アプリケーションクラスですファイル名にドットが入っている問題を解決しました。
RestControllersのリクエストマッピングで{variable:。+}を追加しても同様の問題を解決したことがありましたが、コントローラーがないため、どのように行うのかわかりませんでした。
EDIT:
私はこの構成では検出されませんでした:
@Configuration
class ServletConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(final PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false);
configurer.setUseTrailingSlashMatch(false);
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
今ではすべての* .htmlのに役立つ、page.01.htmlを含め、まだstyle.01.cssではありませんか、 script.01.js。私は別の問題であると仮定し、元のものはContentNegotiationConfigurerによって解決されます。
なぜこのタグはnpmですか?これはnode.jsとは関係ありません。 –
ファイル名にドットを含む静的コンテンツを取得するには、npm run buildコマンドを使用します。 – Marcoc1712
これらのファイルを手作業で作成すると同じことが起こると私は想定しているので、あなたの問題には関係しないと思いますか?そうでない場合は、明示的に言及することが重要です。 –