簡體   English   中英

無法加載ApplicationContext(Spring Boot)

[英]Failed to load ApplicationContext (Spring Boot)

我正在嘗試通過Spring網站上的示例測試我的應用程序。

這些是我的依賴項:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile("org.springframework.boot:spring-boot-starter-security")
    compile('org.springframework.boot:spring-boot-starter-web')
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")
    runtime('org.springframework.boot:spring-boot-devtools')
    runtime('com.h2database:h2')
    runtime('mysql:mysql-connector-java')
    compileOnly('org.projectlombok:lombok')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
}

這是測試類:

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class ProductControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void testHomePage() throws Exception {
        this.mockMvc.perform(get("/")).andDo(print()).andExpect(status().isOk());
    }

}

我收到錯誤:

org.springframework.beans.factory.BeanCreationException:創建在類路徑資源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]中定義的名稱為'entityManagerFactory'的bean時出錯:調用init方法失敗; 嵌套的異常是java.lang.NoClassDefFoundError:javax / xml / bind / JAXBException

java.lang.IllegalStateException:無法加載ApplicationContext

知道是什么原因造成的嗎? 我沒有任何特定的配置文件,只有安全性配置和webconfig。

Webconfig:

    public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/images/**", "/css/**", "/fragments/**")
                .addResourceLocations("classpath:/static/images/", "classpath:/static/css/", "classpath:/fragments/");
    }
}

輸出中的以下行:

java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

告訴我們找不到類javax.xml.bind.JAXBException

如@Antot所述,將以下依賴項添加到您的graddle應該可以解決此問題:

compile('javax.xml.bind:jaxb-api:2.3.0')

對於使用Maven的用戶,請使用以下命令:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM