Spring + Gradle + PostgreSQL を使用しており、新しい Spring ServletDispatcher または HandlerMapping を作成したいと考えています (どちらが最適な選択かわかりません)。
要件は次のとおりです。サブドメイン名に従って、HTTP 要求を別のコントローラーにリダイレクトします。
例えば:
HTTP リクエスト:
aaa.domain.com は、=> website/aaa/
bbb.domain.com => website/bbb/にリダイレクトされます。
どうすればそれを書くことができますか?
私のGradleの依存関係:
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-websocket')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
どうもありがとう!
最初の更新
Springについてもう少し深く調べてみました。そして今、新しい HandlerMapping がより良い選択かもしれないと思います。そこで、 DefaultAnnotationHandlerMappingを書き換えたいと思います。
これはパッケージspring-webmvcのクラスであり、 DispatcherServlet.propertiesで次のように定義されています。
org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
DispatcherServlet.propertiesを直接変更できません。クラスを自分のクラスに置き換えたい場合、どうすればよいでしょうか?
プロジェクトを定義するために、XML の代わりに多くの spring-boot-starter を使用しました。
application.propertiesでorg.springframework.web.servlet.HandlerMappingを定義しようとしましたが失敗しました。