美文网首页
spring boot 问题汇总

spring boot 问题汇总

作者: Mr菜头 | 来源:发表于2020-12-18 11:36 被阅读0次
    • 1、@RunWith 无法加载
      解决方法:
      需要加入依赖:
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    

    同时需要删除 eclipse 自动生成的 junit 依赖


    • 2、@RunWith 注解起什么作用?

      @RunWith就是一个运行器
      @RunWith(JUnit4.class)就是指用JUnit4来运行
      @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境
      @RunWith(Suite.class)的话就是一套测试集合

    其中 @RunWith(SpringRunner.class) == @RunWith(SpringJUnit4ClassRunner.class)

      public final class SpringRunner extends SpringJUnit4ClassRunner
    

    3、spring boot 如何瘦身
    a、在pom.xml 加入 spring 的 打包配置

    <build>
        <plugins>
               <plugin>    
                    <groupId>org.springframework.boot</groupId>     
                    <artifactId>spring-boot-maven-plugin</artifactId>    
                    <configuration>    
                        <mainClass>com.test.testApplication</mainClass>    
                        <layout>ZIP</layout> 
                    </configuration>    
                    <executions>    
                        <execution>    
                            <goals>    
                                <goal>repackage</goal>    
                            </goals>    
                        </execution>    
                    </executions>    
                </plugin>
        <plugins>
    <build>
    

    b、使用 eclipse 中 run as maven clean 清空target
    c、使用 eclipse 中 run as maven install 进行打包
    d、进入 target包 直接把 jar 包 改名为 zip 包


    image.png

    e、打开 改名后的 zip包


    image.png
    image.png

    f、把 lib 包拿出


    image.png

    g、更改 pom.xml

    <build>
        <plugins>
             <plugin>    
                    <groupId>org.springframework.boot</groupId>     
                    <artifactId>spring-boot-maven-plugin</artifactId>    
                    <configuration>    
                        <mainClass>com.eybond.crm.CrmApplication</mainClass>    
                        <layout>ZIP</layout>    
                        <includes>     
                            <include>    
                                <groupId>nothing</groupId>    
                                <artifactId>nothing</artifactId>    
                            </include>      
                        </includes>    
                    </configuration>    
                    <executions>    
                        <execution>    
                            <goals>    
                                <goal>repackage</goal>    
                            </goals>    
                        </execution>    
                    </executions>    
                </plugin>
        <plugins>
    <build>
    

    h、使用 eclipse 中 run as maven clean 清空target,run as maven install 进行打包
    打出的包变小了


    image.png

    启动jar 包,指定依赖包

    java -Dloader.path=/lib -jar /test.jar 
    

    相关文章

      网友评论

          本文标题:spring boot 问题汇总

          本文链接:https://www.haomeiwen.com/subject/ktyxnktx.html