春天开机战到外部tomcat

时间:2016-01-19 15:05:14

标签: java spring tomcat spring-boot

我正在尝试在外部Tomcat服务器上部署我的Spring启动项目。我遵循了所有给出的建议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

所以我使用网址http://128.0.169.5:8082/bqp/

enter image description here

更新:

我的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启动的主要方法轻松部署它。但我应该将它部署在远程服务器上。

Application.class:

@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);
}

}

1 个答案:

答案 0 :(得分:-1)

尝试将此代码放在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>