我正在尝试在外部 Tomcat 服务器上部署我的 Spring boot 项目。我在这里遵循了所有给出的建议 http://docs.spring.io/spring-boot/docs/1.1.4.RELEASE/reference/htmlsingle/#build-tool-plugins-maven-packaging ,但是我有点困惑,因为我将它部署在服务器上并且一切正常,但每次访问任何页面时我都会收到 404 错误。另外,我添加到 application.properties
server.context-path=/bqp
所以我使用这样的 url http://128.0.169.5:8082/bqp/
更新:
我的 spring-config.xml:
<context:component-scan base-package="com.bionic" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
<property name="persistenceUnitName" value="com.bionic.quizzes" />
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="jpaDialect" ref="jpaDialect" />
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="HSQL" />
<property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
</bean>
<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/quizzes" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
此外,我可以通过 Spring boot 的主要方法轻松部署它。但我应该将它部署在远程服务器上。
应用程序类:
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
最佳答案
尝试将此代码放在您的 servlet.xml 中
<bean class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/bqp/"/>
<property name="suffix" value=".jsp"/> //if you are using .jsp
</bean>
关于java - Spring 启动 war 到外部tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34880169/