springboot+activemq+redis整合

2 篇文章 0 订阅
1 篇文章 0 订阅

最近弄个小分布式的工程,记录一次整合过程,最后打包成war包部署到Tomcat当中,持续更新

1.项目结构如图所示

2.pom.xml

 <packaging>war</packaging>

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions><!--去掉有冲突的jar包否则无法启动Tomcat-->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                      <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
                相当于compile,但是打包阶段做了exclude操作-->
            <scope>provided</scope>
        </dependency>
        <!-- 热部署配置 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <!-- <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
        </dependency> -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
            <version>5.15.0</version>
      </dependency>
    </dependencies>
<!--id 与文件夹的名称对应-->
    <profiles>
        <profile>
            <id>dev</id>  <!--开发环境-->
            <properties>
                <deploy.type>dev</deploy.type>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>pro</id> <!--生产环境-->
            <properties>
                <deploy.type>pro</deploy.type>
            </properties>
        </profile>
        <profile>
            <id>test</id> <!--测试环境-->
            <properties>
                <deploy.type>test</deploy.type>
            </properties>
        </profile>
    </profiles>

<build>
        <finalName>springboot</finalName><!--打包后的项目名称-->
        <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
           <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <!-- 打包资源 排除 -->
                    <excludes>
                        <exclude>test/*</exclude>
                        <exclude>pro/*</exclude>
                        <exclude>dev/*</exclude>
                    </excludes>
                </resource>
                <resource>
                    <!-- ${deploy.type} 对应 profile deploy.type -->
                    <directory>src/main/resources/${deploy.type}</directory>
                </resource>
            </resources>

   </build>

3.启动类

/**
 * 以下配置是为了启动springboot,并且可以打包部署到tomcat当中
 */
@EnableScheduling
@SpringBootApplication
public class App extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(
            SpringApplicationBuilder builder) {
        return builder.sources(App.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

4.打包(profiles中的参数为test或者pro,为了根据不同环境打包不同的配置文件)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值