首页 文章

Jenkins无法创建entityManagerFactory

提问于
浏览
0

我为我的应用程序创建了以下测试:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class exampleTests {

    @Autowired
    private WebApplicationContext context;

    private MockMvc mvc;
    private WebClient webClient;

    @LocalServerPort
    int port;

    @Before
    public void setup() {
        this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
        this.webClient = MockMvcWebClientBuilder.webAppContextSetup(context, springSecurity()).build();
    }

    @Test
    public void mvcTest() throws Exception {
        mvc.perform(get("/")).andExpect(status().isOk());
    }

    @Test
    public void clientTest() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
        HtmlPage loginPage = webClient.getPage("http://localhost:"+port+"/app/");
        List<DomElement> pageList = loginPage.getElementsByTagName("h1");
        DomElement page = pageList.get(0);
        String text = page.getTextContent();
        assertThat(text).isEqualTo("Please log in");
    }
}

当我在本地机器上执行mvn安装时,一切正常 . 但是Jenkins在构建之后返回以下堆栈跟踪:

org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]中定义名称为'entityManagerFactory'的bean创建错误:init方法的调用失败;嵌套异常是javax.persistence.PersistenceException:无法解析org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1710)〜[spring-beans-5.0.4.RELEASE.jar]中的持久性单元根URL :5.0.4.RELEASE] org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org org.springframework.beans.factory.support中的.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] . org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton中的AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:312)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE](DefaultSingletonBeanRegistry . java:228)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] a org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.springframework.beans.factory . org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1085)中的support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)〜[spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] )〜[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858)〜[spring-context-5.0.4 . RELEASE.jar:5.0.4.RELEASE]在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)〜[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE] at at组织中的org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)〜[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE] .springframework.boot.SpringApplication.refresh(SpringApplication.java:752)〜[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java: 388)〜[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]在org.springframework.boot.SpringApplication.run(SpringApplication.java:327)〜[spring-boot-2.0.0.RELEASE .jar:2.0.0.RELEASE] at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:138)[spring-boot-test-2.0.0.RELEASE.jar:2.0.0.RELEASE ] org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.springframework.test.context . org.springframework.test.context.support.DefaultTestContext.getAppli中的cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE]在org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)中的cationContext(DefaultTestContext.java:107)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] [spring] -test-5.0.4.RELEASE.jar:5.0.4.RELEASE] at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)[spring-test-5.0.4.RELEASE.jar :5.0.4.RELEASE] at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:44)[spring-boot-test-autoconfigure-2.0.0.RELEASE.jar:2.0.0.RELEASE在org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:242)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] atorg.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.springframework.test.context.junit4 . SpringJUnit4ClassRunner $ 1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12 )[junit-4.12.jar:4.12] at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.springframework.test.context.junit4 .SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)[junit -4.12.jar:4.12]在org.junit.r unners.ParentRunner $ 1.schedule(ParentRunner.java:71)[junit-4.12.jar:4.12] org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)[junit-4.12.jar:4.12] at org .junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)[junit-4.12.jar:4.12] at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)[junit-4.12.jar: 4.12]在org.springframework.test的org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE] org.junit.runners.ParentRunner.run上的.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)[spring-test-5.0.4.RELEASE.jar:5.0.4.RELEASE](ParentRunner.java :363)[junit-4.12.jar:4.12] org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)[spring-test-5.0.4.RELEASE.jar:5.0.4 . 发布在org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.j) ava:369)[surefire-junit4-2.20.1.jar:2.20.1] org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:275)[surefire-junit4-2.20.1.jar :2.20.1] org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:239)[surefire-junit4-2.20.1.jar:2.20.1] org.apache.maven.surefire . junit4.JUnit4Provider.invoke(JUnit4Provider.java:160)[surefire-junit4-2.20.1.jar:2.20.1] org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:373)[surefire -booter-2.20.1.jar:2.20.1]在org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:334)[surefire-booter-2.20.1.jar:2.20.1] at at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:119)[surefire-booter-2.20.1.jar:2.20.1]在org.apache.maven.surefire.booter.ForkedBooter.main( ForkedBooter.java:407)[surefire-booter-2.20.1.jar:2.20.1]引起:javax.persistence.PersistenceException:无法解析持久性uni org.springframework.orm上org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:637)〜[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]的根URL org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.afterPropertiesSet中的.jpa.persistenceunit.DefaultPersistenceUnitManager.preparePersistenceUnitInfos(DefaultPersistenceUnitManager.java:459)〜[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]在Org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:328)〜[spring-orm]的DefaultPersistenceUnitManager.java:440)~ [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE] -5.0.4.RELEASE.jar:5.0.4.RELEASE]在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)〜[spring-beans-5.0.4.RELEASE.jar: 5.0.4.RELEASE]在org.springframework.beans.factory.s upport.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)~ [spring-beans-5.0.4.RELEASE.jar:5.0.4.RELEASE] ...省略了44个常见帧引起的:java.io.FileNotFoundException:类路径resource []无法解析为URL,因为它在org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)〜[spring-core-5.0.4.RELEASE.jar:5.0.4中不存在 . 发布]org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.determineDefaultPersistenceUnitRootUrl(DefaultPersistenceUnitManager.java:633)〜[spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE] ...省略了49个常用帧

我的测试有什么问题,Jenkins无法执行它?

3 回答

  • 0

    这可能是因为 Spring 季启动版本升级 . 我发现this thread与你的问题类似,我找到的解决方案就是这个 . 希望这对你有所帮助 .

    必须在应用程序类上设置@EnableAutoConfiguration(exclude = HibernateJpaAutoConfiguration.class),并且必须在应用程序属性/ yml中设置spring.data.jpa.repositories.enabled = false .

  • 0

    我在这里找到了解决方案:https://jira.spring.io/browse/SPR-15304

    当我输入mvn clean install -f ./pom.xml而不是mvn clean install时,我可以在本地重现问题 . 在Jenkins中,我设置了pom文件的自定义路径,因为pom文件不在存储库的根目录中 . (路径类似于:./ pathToPomFile/pom.xml解决方案是删除Jenkins中pom.xml的自定义路径,并将整个代码结构移动到存储库的根目录 .

  • 0

    我也有这个问题,但重新组织我的回购(就像在“接受的答案”中)不是一个选择 . 我最终使用“执行shell”构建步骤而不是内置Maven步骤,我的脚本只是“cd someDir; mvn clean install” .

    像魅力一样工作!

相关问题