2017-11-21 2 views
0

간단한 스프링 부트 프로젝트에서 메이븐 테스트를하는 동안 오류가 발생했습니다. Maven 유효성 검사 및 컴파일을 실행할 수 있습니다.스프링 부트 - 메이븐 빌드 에러

소스 코드는 다음과 같습니다 :

package com.example.demo; 
 

 
import org.springframework.boot.SpringApplication; 
 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
 

 
@SpringBootApplication 
 
public class Microservice1Application { 
 

 
\t public static void main(String[] args) { 
 
\t \t SpringApplication.run(Microservice1Application.class, args); 
 
\t } 
 
}

테스트 코드는 다음과 같습니다 :

package com.example.demo; 
 

 
import org.junit.Test; 
 
import org.junit.runner.RunWith; 
 
import org.springframework.boot.test.context.SpringBootTest; 
 
import org.springframework.test.context.junit4.SpringRunner; 
 

 
@RunWith(SpringRunner.class) 
 
@SpringBootTest 
 
public class Microservice1ApplicationTests { 
 

 
\t @Test 
 
\t public void contextLoads() { 
 
\t } 
 

 
}

내가 점점 오전 오류가아래 :

------------------------------------------------------------------------------- 
 
Test set: com.example.demo.Microservice1ApplicationTests 
 
------------------------------------------------------------------------------- 
 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.895 sec <<< FAILURE! - in com.example.demo.Microservice1ApplicationTests 
 
contextLoads(com.example.demo.Microservice1ApplicationTests) Time elapsed: 0.011 sec <<< ERROR! 
 
java.lang.IllegalStateException: Failed to load ApplicationContext 
 
\t at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) 
 
\t at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) 
 
\t at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
 
\t at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) 
 
\t at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
 
\t at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) 
 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
 
\t at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) 
 
\t at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) 
 
\t at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) 
 
\t at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) 
 
\t at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) 
 
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
 
\t at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:264) 
 
\t at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:228) 
 
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 
 
\t at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) 
 
\t at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)

당신이 도와 주실 수 있습니까?

+1

_There의 일환으로 속성과 "hibernate.driver"로 "hibernate.dialect"을 추가 것을 볼 수있다

@Configuration @EnableTransactionManagement @PropertySource(value = { "classpath:hibernate.properties" }) public class HibernateConfiguration { @Autowired private Environment environment; @Bean public LocalSessionFactoryBean sessionFactory() { LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); sessionFactory.setHibernateProperties(hibernateProperties()); return sessionFactory; } @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(environment.getRequiredProperty("hibernate.connection.driver")); dataSource.setUrl(environment.getRequiredProperty("hibernate.connection.url")); dataSource.setUsername(environment.getRequiredProperty("hibernate.connection.username")); dataSource.setPassword(environment.getRequiredProperty("hibernate.connection.password")); return dataSource; } private Properties hibernateProperties() { Properties properties = new Properties(); properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect")); properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql")); properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql")); properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto")); return properties; } @Bean @Autowired public HibernateTransactionManager transactionManager(SessionFactory s) { HibernateTransactionManager txManager = new HibernateTransactionManager(); txManager.setSessionFactory(s); return txManager; } } 

:

마지막으로 최대 절전 모드 설정은 다음과 같을 수 있습니다 시험 실패입니다. 먼저 어떤 테스트가 실패하는지 확인하십시오. _ 개별 테스트 결과에 대한 target ... surefire-reports를 참조하십시오 _ – pirho

+0

다음과 같이 오류가 표시됩니다 테스트 세트 : com.example.demo.Microservice1ApplicationTests ---------------- -------------------------------------------------- ------------- 테스트 실행 : 1, 실패 : 0, 오류 : 1, 건너 뛰기 : 0, 경과 시간 : 2.702 초 <<< 실패! - com.example.demo.Microservice1ApplicationTests에서 contextLoads (com.example.demo.Microservice1ApplicationTests) 경과 시간 : 0.001 초 <<< 오류! java.lang.IllegalStateException : ApplicationContext를로드하지 못했습니다. – DS2017

+0

이 항목을 질문에 추가하고 주석이 아닌 형식으로 올바르게 입력하십시오. 질문을 수정하십시오. 실패한 테스트 케이스를 찾으십시오. 그들은 이유 때문에 실패하거나 유효한 시험이 아닙니다. – pirho

답변

1

그냥 최신가 "에 의한"읽기 :

Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) 

을 그래서 당신은 이런 구성 XML이나 YAML 뭔가 어딘가에 필요 : 나는 MySQL의 사투리도 I을 사용

hibernate.dialect=org.hibernate.dialect.MySQLDialect 
hibernate.connection.driver=com.mysql.jdbc.Driver 

MySQL 드라이버를 지정하십시오 (귀하의 경우 적절한 데이터베이스를 확인해야합니다). 당신은 내가 데이터 소스

+0

안녕하세요, Maven 저장소를 .m2/repository로 기본 설정하고 Maven 저장소를 다시 색인하고 이 문제가 해결되었습니다. 이상한,,, – DS2017