首页 \ 问答 \ 将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 ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)