プロジェクト要件のため、Tomcatを実行できないサーバーにSpringアプリケーションをデプロイし、WildFlyのみを実行できるようにする必要があります。私がTomcatで動作する非常に単純なプロジェクトを持っていて、ルートURLが(localhost:8080)
に当たったとき、それは私のindex.html
をレンダリングしました。 WildFlyに移行してプロジェクトの構造をリファクタリングした後、localhost:8080
はindex.html
をレンダリングしなくなりましたが、ははまだ他のURLに到達しません。ワイルドフライの春は、ルートURLがヒットしたときにindex.htmlをレンダリングしない
私はこのようBrassDucks/src/main/webapp/WEB-INF/jboss-web.xml
下jboss-web.xml
ファイルを実装しようとしました:
<jboss-web>
<context-root>Brass-Ducks</context-root>
</jboss-web>
Brass-Ducks
が
artifactID
ある
が、無駄にします。
私ApplicationConfig.java
package brass.ducks;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class ApplicationConfig extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(ApplicationConfig.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
private static Class<ApplicationConfig> applicationClass = ApplicationConfig.class;
}
@RestController
class GreetingController {
@RequestMapping("/hello/{name}")
String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
}
を考えると、私のController.java
package brass.ducks.application;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class Controller {
@RequestMapping("/greet")
@ResponseBody
public String greeting() {
return "Hello, there.";
}
}
そして最後に、それは、私のフォルダ構造の関連する必要があります考えてみます。
localhost:8080/greet
リターン"こんにちは、そこに"とlocalhost:8080/hello/name
"Helloの名前"を返します。これをどうすれば解決できますか?この線に沿って何かが動作するはずですあなたの正確な構成に応じて
web.xmlファイルを投稿できますか? –
@GergelyBacsoああ、私はそれらの1つを持っていません... – Nanor
それはあなたのために物事を行っている春になるよ。余分なコントローラを追加し、 '/'パスをindex.htmlにマッピングすることを考えてみませんか? –