gpt4 book ai didi

java - 无法加载ApplicationContext(Spring Boot)

转载 作者:太空宇宙 更新时间:2023-11-04 10:29:50 25 4
gpt4 key购买 nike

我正在尝试按照 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: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

java.lang.IllegalStateException: Failed to load ApplicationContext

知道是什么原因造成的吗?我没有任何特定的配置文件,只有安全配置和 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>

关于java - 无法加载ApplicationContext(Spring Boot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50140050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com