你好,我正在尝试学习使用eclipse的一个非常简单的应用程序的通配符和trying引导。项目名称是springboot-test。包括主方法类在内的所有类都在同一个包中。
Main方法类称为'App‘,它有以下代码:
@SpringBootApplication
@RestController
public class App {
@Autowired
private Student student;
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@RequestMapping("/index")
public String sayHello()
{
return "hello from spring boot" + this.student.showAddress();
}
}以下是服务器日志:
11:36:57,281 INFO org.wildfly.extension.undertow WFLYUT0021:注册的web上下文:‘/springboot-test-0.0.1-快照’用于服务器“默认-服务器” 11:36:57,301 INFO org.jboss.as.server WFLYSRV0010:已部署的“springboot启动-测试-0.0.1-SNAPSHOT.war”(运行时-名称:"springboot-test-0.0.1-SNAPSHOT.war") 11:36:57,408 INFO org.jboss.as.server WFLYSRV0212:恢复服务器 11:36:57,411信息org.jboss.as WFLYSRV0060: Http管理界面监听http://127.0.0.1:8181/management 11:36:57,412 INFO org.jboss.as WFLYSRV0051:管理控制台监听http://127.0.0.1:8181 11:36:57,412 INFO org.jboss.as WFLYSRV0025: WildFly Full 11.0.Full (WildFly Core 3.0.8 Full)从11393 on开始-在732个服务中启动504个(353个服务是懒惰的、被动的或按需服务)
我访问的网址是:http://localhost:8080/springboot-test/index
发布于 2018-04-26 08:35:25
由于您使用通配符进行部署,我希望您正在生成war文件,服务器日志似乎支持我的语句
你有SpringBootServletInitializer课程吗?如果不是,那就是问题所在
你需要这样的东西
@SpringBootApplication
@RestController
public class ServletInitializer extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(ServletInitializer.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ServletInitializer.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException{
super.onStartup(servletContext);
}
@RequestMapping("/index")
public String sayHello(){
return "hello from spring boot" + this.student.showAddress();
}
}我不确定在一个类中注释@SpringBootApplication和@RestController是否有任何问题。但我的建议是把它分开维护
@RestController
public class Mycontroller{
@RequestMapping("/index")
public String sayHello(){
return "hello from spring boot" + this.student.showAddress();
}
}发布于 2018-06-18 13:07:22
您的服务器日志显示:
11:36:57,281 INFO org.wildfly.extension.undertow WFLYUT0021:注册的web上下文:‘/springboot-test-0.0.1-快照’用于服务器“默认-服务器”
它应该可以访问:http://localhost:8080/springboot-test-0.0.1-SNAPSHOT/index
如果您想注册您的地址,请将Maven文件配置为使用<finalName>${project.artifactId}</finalName>。
https://stackoverflow.com/questions/48700147
复制相似问题