首页 \ 问答 \ 将Spring启动战争部署到Tomcat 8(Deploying Spring boot war to Tomcat 8)

将Spring启动战争部署到Tomcat 8(Deploying Spring boot war to Tomcat 8)

我想将我的Spring启动应用程序(.war)部署到外部Tomcat-Server。 我的应用程序在我的本地Tomcat 8和jdk 8中运行良好。此外,我们正在使用maven和

现在我们必须从头开始设置整个服务器,我们尽力做到最好,但应用程序将找不到任何服务。 我们可以调用静态html,css和js文件。 至于我们想要调用服务,我们会收到404错误。

任何人都可以通过部署战争向我展示设置tomcat的一步一步吗?

这是我的开始类:

@PropertySources({
        @PropertySource("classpath:/application.properties"),
        @PropertySource("classpath:/messages_de.properties")
})
@SpringBootApplication
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication springApplication = new SpringApplication(Application.class);
        springApplication.run(args);
    }
}

这是pom.xml ......

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.quanto</groupId>
    <artifactId>QuantoSpringMVC</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>QuantoSpringMVC Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.6.1-RC1</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        <!-- Used for generating hibernate-model classes >>> -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>4.3.2.Final</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.eclipse.equinox</groupId>
            <artifactId>app</artifactId>
            <version>1.3.200-v20130910-1609</version>
        </dependency>
        <!-- <<< -->
        <!-- SPRING DEPENDENCIES/REPO/PLUGINS STARTS HERE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <!-- SECURITY START -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- SECURITY ENDS -->
        <!-- Authentification (Access Directory...) -->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>0.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper.extensions</groupId>
            <artifactId>modelmapper-spring</artifactId>
            <version>0.7.5</version>
        </dependency>
    </dependencies>
    <properties>
        <springframework.version>4.2.4.RELEASE</springframework.version>
        <java.version>1.7</java.version>
        <tomcat.version>8.0.32</tomcat.version>
    </properties>
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>QuantoSpringMVC</finalName>
    </build>
</project>

I want to deploy my Spring boot application (.war) to an external Tomcat-Server. My application works fine in Eclipse with my local Tomcat 8 and jdk 8. Furthermore, we are using maven and

Now we had to setup a whole server from scratch and we tried to do our best, but the application won't find any Services. We just can call static html, css and js files. As far as we want to call a service we get an 404 error.

Can anyone show me a step-by-step setting up tomcat with deploying the war?

Here is my startclass:

@PropertySources({
        @PropertySource("classpath:/application.properties"),
        @PropertySource("classpath:/messages_de.properties")
})
@SpringBootApplication
public class Application {
    public static void main(String[] args) throws Exception {
        SpringApplication springApplication = new SpringApplication(Application.class);
        springApplication.run(args);
    }
}

Here is the pom.xml...

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.quanto</groupId>
    <artifactId>QuantoSpringMVC</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>QuantoSpringMVC Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.6.1-RC1</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        <!-- Used for generating hibernate-model classes >>> -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>4.3.2.Final</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.eclipse.equinox</groupId>
            <artifactId>app</artifactId>
            <version>1.3.200-v20130910-1609</version>
        </dependency>
        <!-- <<< -->
        <!-- SPRING DEPENDENCIES/REPO/PLUGINS STARTS HERE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jcl-over-slf4j</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <!-- SECURITY START -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- SECURITY ENDS -->
        <!-- Authentification (Access Directory...) -->
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>0.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper.extensions</groupId>
            <artifactId>modelmapper-spring</artifactId>
            <version>0.7.5</version>
        </dependency>
    </dependencies>
    <properties>
        <springframework.version>4.2.4.RELEASE</springframework.version>
        <java.version>1.7</java.version>
        <tomcat.version>8.0.32</tomcat.version>
    </properties>
    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>QuantoSpringMVC</finalName>
    </build>
</project>

原文:https://stackoverflow.com/questions/35733107
更新时间:2024-01-01 14:01

最满意答案

是的,你必须catch异常,你为上下文提交SaveChanges() 。 你可以尝试这样的事情。

try
{
    using (MyEntities context = new MyEntities ())
    {
        // do your code
        MyConfiguration.SuspendExecutionStrategy = true;
        context.Entity.Add(entity);
        context.SaveChanges();
    }
}
catch (Exception ex)
{
    logger.Warn("Connection error with database server.", ex);
}
finally
{
    //Enable retries again...
    MyConfiguration.SuspendExecutionStrategy = false;
}

Yes you have to catch the Exception where you commit the SaveChanges() for the context. You can try something like this.

try
{
    using (MyEntities context = new MyEntities ())
    {
        // do your code
        MyConfiguration.SuspendExecutionStrategy = true;
        context.Entity.Add(entity);
        context.SaveChanges();
    }
}
catch (Exception ex)
{
    logger.Warn("Connection error with database server.", ex);
}
finally
{
    //Enable retries again...
    MyConfiguration.SuspendExecutionStrategy = false;
}

相关问答

更多
  • 解决方案是重新传递,即二级重试。 这是文档 。 有两种方法可以使用它: 来自消费者的明确重新传递,称为例外: public async Task Consume(ConsumeContext context) { try { // try to update the database } catch (CustomerNotFoundException exception) { // sche ...
  • 简言之: 发生这种情况的原因是,在写入步骤SB中发生错误时,不知道哪个对象导致了异常,因此执行了回滚,并且最后一个未完成的块的每个单项都被作为小块重新处理/编写以检测哪个对象是原因的主写错误。 你可以在这里阅读更多(带图) In few words: This happens because when an error occured in write step SB doesn't know which object caused the exception so a rollback is perfor ...
  • 是的,你必须catch异常,你为上下文提交SaveChanges() 。 你可以尝试这样的事情。 try { using (MyEntities context = new MyEntities ()) { // do your code MyConfiguration.SuspendExecutionStrategy = true; context.Entity.Add(entity); context.SaveChanges ...
  • 好的,我找到了一个解决方案: using(var sqlConnection = new ReliableSqlConnection(_connectionString, _connectionRetry, _commandRetry) { var command = sqlConnection.CreateCommand(); command.CommandText = "..."; sqlConnection.Open(); var dataReader = sqlCo ...
  • 就像@Borgleader指出的那样, flag变量是不必要的。 如果计数仍大于零,您可以坚持使用break指令并在循环后检查。 如果是这样,意味着您的任务成功。 unsigned int count = 5; while(count > 0) { DataOperation opt = DataUser::Insert(data_point); if(opt == DataOperation::DataEnum) { UserPointData exist = DataUs ...
  • 如果捕获NoNetworkAvailableException则可以避免重试。 如果您知道以下尝试将失败,请勿重试。 我会使connectionFailedMaximumAllowedRetries()成为常量。 我怀疑你需要在任何时候改变变量。 实现指数退避 。 你可以让它重试10次。 每次,您将延迟乘以2(上限为几分钟)。 例如: 尝试通话 - 失败 等一下 尝试通话 - 失败 等2秒 尝试通话 - 失败 等4秒 ... 尝试通话 - 成功 这是非常典型的行为。 如果发生短暂中断,将很快再次拨打电话并成 ...
  • 据我所知,SDK不支持可配置的重试策略(不要与队列客户端的重试策略混淆)。 如果我理解你的意图,你会想要捕获异常,调用DeleteMessage将其从队列中拉出来,并重新排队具有较长初始可见性延迟的相同消息,然后重新抛出异常。 您需要跟踪消息本身中的出列数,因为删除消息将删除DequeueCount。 如果要退避并重试导致异常的操作(同时保留队列消息),可以调用UpdateMessage来扩展可见性超时,然后最终抛出异常。 As far as I know, the SDK does not support ...
  • 非阻塞重试策略现在是CE的一部分 (从3.2.0开始)。 为了让您的组件与Mule的生命周期和重试策略集成,我建议您使用DevKit将其开发为Mule模块(请参阅http://blogs.mulesoft.org/introducing-the-new-devkit/中的 “Mule的生命周期支持”) 。 虽然作为“API连接器工具包”销售,但DevKit可以做更多的事情...... 当然,这将使您的组件Mule具体化,但有利于使其成为Mule基础设施的一等公民。 Non-blocking retry po ...
  • 即使JdbcConnector具有init / start / stop / dispose方法的noops,也应该在AbstractConnector.connect()记录“Connecting:”之后立即调用重试策略模板。 也许你想在这个地方断点并坚持下去? 如果使用线程重试策略,即使连接器发生故障,Mule也会启动。 取决于此连接器的入站端点将不会启动,因此使用它们的流将不会被触发,直到连接器可以启动。 出站端点将抛出异常:由您来处理这种情况,无论是直到成功还是异常策略执行一些自定义的问题处理。 E ...
  • 在复制因子为3且读取一致性级别为QUORUM的单个数据中心群集中,给定行的3个副本中的2个必须响应以完成读取请求。 如果联系的副本具有不同版本的行,则具有最新版本的副本将返回所请求的数据。 在后台,检查第三个副本与前两个副本的一致性,如果需要,将为过期副本启动读取修复。 阅读一致性级别示例 读取修复还取决于在columnfamily级别设置的read_repair_chance的值。 默认情况下,该值为0.10 ,这意味着100个读取请求中的10个将启动读取修复 In a single data cente ...

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的