我有有一个基本URI为名为“springapp”弹簧启动应用程序:Tomcat的使用战争的名称作为基本URL春季启动
http://localhost:8080/
当我运行它作为一个独立的应用程序它工作正常。但是,当我运行它像“运行 - >服务器上运行”在Eclipse中,它会追加战争名称springapp-1.0-快照和基本URL将成为:
http://localhost:8080/springapp-1.0-snapshot
有什么办法我可以解决此问题。我想要的URI是
http://localhost:8080/springapp
我尝试了所有在下面我application.properties配置,但没有一次成功:
spring.webservices.path=/springapp
server.tomcat.basedir=/springapp
spring.jersey.application-path=/springapp
server.contextPath=/springapp
server.servlet-path=/springapp
这是我的入门级:
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@ImportResource("classpath:spring-config.xml")
public class SpringAppStarter extends SpringBootServletInitializer {
private static final Logger GENERAL_LOG = LogManager.getLogger(SpringAppStarter .class);
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(SpringAppStarter.class);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
GENERAL_LOG.info("Starting Spring Service App");
SpringApplication.run(SpringAppStarter .class, args);
}
}
和我的请求映射类:
@RestController
@RequestMapping("/Customers")
public class SpringAppResource {
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
我也addded上下文配置在META-INF文件夹:
<Context>
<context docBase="springapp" path="/springapp" reloadable="true"/>
</Context>
我使用Maven构建项目。而且我不想更改服务名称。我需要在应用程序本身的某处提供上下文路径。不能有任何依赖于服务器。我应该提供所有配置,因此在部署之后不需要进行配置。
的Tomcat默认使用WAR文件名作为上下文路径。快速搜索给我这个:http://stackoverflow.com/q/7276989/395202它告诉你如何使用你的应用程序的上下文路径,或https://tomcat.apache.org/tomcat-5.5-doc/config/ context.html如何在Tomcat中设置上下文路径 –
谢谢。理想情况下,这是我们为常规Web服务所做的。我已经尝试过,但它不适用于春季启动。 – Madie
我认为这与Spring Boot没有任何关系。在Web应用程序(这里使用Spring Boot)可以执行任何操作之前,上下文路径应该由容器决定。 –