我有有一個基本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)可以執行任何操作之前,上下文路徑應該由容器決定。 –