[英]Spring on Wildfly not rendering index.html when root URL hit
Due to project requirements I have to deploy a Spring application to a server incapable of running Tomcat and only capable of running WildFly. 由于项目要求,我必须将Spring应用程序部署到无法运行Tomcat的服务器,并且只能运行WildFly。 When I had a very simple project running on Tomcat and the root URL was hit
(localhost:8080)
it rendered my index.html
. 当我在Tomcat上运行一个非常简单的项目并且命中了根URL
(localhost:8080)
它呈现了我的index.html
。 Since migrating to WildFly and refactoring the structure of my project, localhost:8080
no longer renders the index.html
but I can still reach other URLs. 由于迁移到WildFly并重构我的项目结构,
localhost:8080
不再呈现index.html
但我仍然可以访问其他URL。
I've tried to implement a jboss-web.xml
file under BrassDucks/src/main/webapp/WEB-INF/jboss-web.xml
like this: 我试过在
BrassDucks/src/main/webapp/WEB-INF/jboss-web.xml
下实现一个jboss-web.xml
文件,如下所示:
<jboss-web>
<context-root>Brass-Ducks</context-root>
</jboss-web>
Where Brass-Ducks
is the artifactID
but to no avail. Brass-Ducks
是artifactID
但无济于事。
Consider my ApplicationConfig.java
考虑一下我的
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 + "!";
}
}
and consider my Controller.java
并考虑我的
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.";
}
}
And finally should it be relevant, my folder structure: 最后应该是相关的,我的文件夹结构:
localhost:8080/greet
returns "Hello, there" and localhost:8080/hello/name
returns "Hello name". localhost:8080/greet
返回“Hello,there”和localhost:8080/hello/name
返回“Hello name”。 How can I fix this? 我怎样才能解决这个问题?
Depending on your exact configuration something along the lines of this should work: 根据您的确切配置,这应该是有用的:
@Controller
public class LandingPageController {
@RequestMapping({"/","/home"})
public String showHomePage(Map<String, Object> model) {
return "/WEB-INF/index.html";
}
}
This is going to explicitly map /
to index.html
. 这将明确映射
/
到index.html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.