当前位置: 首页 > 知识库问答 >
问题:

Spring Boot从战争走向战争

司徒云
2023-03-14

我尝试使用Spring Boot 2.0.2从战争转移到罐子,并且在使用故障安全进行maven测试时遇到了问题。

我看到两种错误:

> < li>

无法找到@SpringBootConfiguration,您需要使用@ContextConfiguration或@SpringBootTest

< code > Java . lang . noclassdeffounderror ,其中列出了我的一个bean类

当我在 IntelliJ 中运行这些测试时,一切正常,但它们在 maven 中失败。与此同时,当我回到建立战争而不是罐子时,一切都有效。

通过从战争转移到jar,我的意思是在Spring启动专家插件中添加一个重新打包目标:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <skip>${spring.boot.skip}</skip>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>springloaded</artifactId>
                    <version>1.2.6.RELEASE</version>
                </dependency>
            </dependencies>
        </plugin>

并从具有main方法的类中删除扩展SpringBootServletOrializer,并将confiure方法移动到main方法中:

@Import(JpaAuditingHandlerRegistrar.class)
@EnableTransactionManagement
@EnableCaching
@Lazy
public class App {

public static void main(String[] args) {
    configure(new SpringApplicationBuilder(App.class))
        .run(args);
}


private static SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    String env = System.getenv("ENV");
    if (env != null) {
        if (Collections.disjoint(List.of(PRODUCTION), List.of(pulsarEnv))) {
            throw new IllegalArgumentException(
                String.format("Unknown ENV provided: %s", env)
            );
        }
        application.profiles(
            env,
            Profiles.METRICS
        );
    }
    return application;
}


public static void main(String[] args) {
    configure(new SpringApplicationBuilder(App.class))
        .run(args);
}

我的测试类注释为:

@EnableConfigurationProperties
@TestExecutionListeners(listeners = {
    DirtiesContextTestExecutionListener.class,
    DirtiesContextBeforeModesTestExecutionListener.class,
    ServletTestExecutionListener.class,
    DependencyInjectionTestExecutionListener.class,
    TransactionalTestExecutionListener.class,
    MockitoTestExecutionListener.class
})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Import(TestConfiguration.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)

另一个难题,当我使用

mvn clean test-compile failsafe:integration-test

它们都可以工作,所以只有在mvn clean install的情况下才会失败,为什么?

共有1个答案

林和煦
2023-03-14

好吧,所以问题是我用的是故障保护2.19.1,这个版本自Spring启动1.4 . x:https://github.com/spring-projects/spring-boot/issues/6254以来就有问题

解决方案是将故障保护降级到2.18,升级它(但是另一组问题出现)或添加

<classifier>exec</classifier>

对于spring-boot-maven-plugin的配置部分,在我的例子中是:org . spring framework . boot spring-boot-maven-plugin $ { spring . boot . skip } exec build-info org . spring framework spring loaded 1 . 2 . 6 . release

 类似资料:
  • 我有一个关于部署我的应用程序的问题。向jboss7开战。 我的测试环境: OS:Ubuntu12.10 Eclipse:Eclipse Juno(Eclipse 4.2) JBoss:JBoss AS 7.1.1最终版 JBoss工具:JBoss工具4 JDK版本:JDK 7 如果使用默认服务器配置,当我启动服务器时,它将成功启动,我的应用程序也将启动。战争可以正常进行 请参阅此屏幕截图 我在服务

  • 我一直在努力研究如何使用maven overlay插件将项目排除在爆炸战争之外。 我有以下内容: xml和applicationcontext.xml可以很好地排除,但它们位于:${basedir}/src/main/webapp/web-inf/下 无论我尝试什么,这些文件是静止的,覆盖,尽管排除。

  • 1984年1月,Richard Stallman 辞去了 MIT 的工作,他担心 MIT 会要求产品的所有权,会给产品强加入自己的销售条件,最终又会成为专有软件。一开始, GNU 计划只有他一个人。他发现自己原来在人工智能实验室的办公室,还没有分给其他人用时,他就每天晚上溜进去工作。久而久之,白天他也跑去用实验室里的电脑。 当时人工智能实验室主任 PatrickH. Winston 并不干涉。因为

  • 问题内容: 相同的.war文件可以很好地部署到Glassfish v2.1上。我不知道上一次尝试v3,但我想检查一下热部署功能,因为有传言说它可以在glassfish v3的netbeans 6.8中使用。因此,我像往常一样进行部署,并收到以下错误消息: 我不明白为什么它抱怨任何与EJB相关的东西,因为这是一个.war文件。有任何想法吗? 更新: 我对glassfish提出了一个错误:https

  • 问题内容: 我有一台装有Ubuntu 12.04的计算机,并且已经安装了Jenkins ver。1.424.6根据 本指南 使用apt-get ,但是有一个新版本: 如果按下载,我会得到一个jenkins.war文件…但是如何使用它来升级当前安装?还是在apt存储库更新之前不可能? 问题答案: 您可以使用新文件覆盖现有文件,然后重新启动Jenkins。 该文件通常位于中。 如果您的系统不是这种情况