2016-10-25 2 views
0

스프링 부트가있는 JHipster 코드 생성기로 백엔드로 작성된 작은 응용 프로그램이 있습니다.JUnit 스프링 부트 응용 프로그램 - 필드를 자동 줄 바꿈하지 못했습니다.

내 간단한 응용 프로그램/통합 테스트를 작성하려고하는데 오류가 있습니다 : Could not autowire. No beans of <type> found. IntelliJ IDE, 최신 버전을 사용하고 있습니다. 여기에 제 코드 조각이 있습니다 :

package com.logate.adminpanel.web.rest; 

import com.logate.adminpanel.CrmScoringApp; import 
com.logate.adminpanel.repository.CityRepository; import 
com.logate.adminpanel.service.CityService; import org.junit.Test; 
import org.junit.runner.RunWith; import 
org.springframework.boot.test.SpringApplicationConfiguration; import 
org.springframework.test.context.ContextConfiguration; import 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 
import org.springframework.test.context.web.WebAppConfiguration; 
import org.springframework.transaction.annotation.Transactional; 
import org.springframework.util.Assert; 

import javax.inject.Inject; 

@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = CrmScoringApp.class) 
@WebAppConfiguration 
public class CityRestTest { 

    @Inject 
    private CityService cityService; 

    @Inject 
    private CityRepository cityRepository; 

    @Test 
    public void test() 
    { 
     Assert.isNull(null); 
    } 
} 

여기서 문제는 무엇인지 알아낼 수 없습니다. 도시 서비스 클래스 여기

package com.logate.adminpanel.repository; 

import com.logate.adminpanel.domain.City; 
import org.springframework.data.jpa.repository.JpaRepository; 

/** 
* Spring Data JPA repository for the City entity. 
*/ 
public interface CityRepository extends JpaRepository<City,Long> { 

} 

된다 :

package com.logate.adminpanel.service; 

import com.logate.adminpanel.domain.City; 
import com.logate.adminpanel.repository.CityRepository; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.data.domain.Page; 
import org.springframework.data.domain.Pageable; 
import org.springframework.stereotype.Service; 
import org.springframework.transaction.annotation.Transactional; 

import javax.inject.Inject; 

/** 
* Service Implementation for managing City. 
*/ 
@Service 
@Transactional 
public class CityService { 

    private final Logger log = LoggerFactory.getLogger(CityService.class); 

    @Inject 
    private CityRepository cityRepository; 

    /** 
    * Save a city. 
    * 
    * @param city the entity to save 
    * @return the persisted entity 
    */ 
    public City save(City city) { 
     log.debug("Request to save City : {}", city); 
     City result = cityRepository.save(city); 

     return result; 
} 


    @Transactional(readOnly = true) 
    public Page<City> findAll(Pageable pageable) { 
     log.debug("Request to get all Cities"); 
     Page<City> result = cityRepository.findAll(pageable); 
     return result; 
    } 

    @Transactional(readOnly = true) 
    public City findOne(Long id) { 
     log.debug("Request to get City : {}", id); 
     City city = cityRepository.findOne(id); 
     return city; 
    } 

    public void delete(Long id) { 
     log.debug("Request to delete City : {}", id); 
     cityRepository.delete(id); 
    } 
} 

스택 추적 :

다음
package com.logate.adminpanel; 

import com.logate.adminpanel.config.Constants; 
import com.logate.adminpanel.config.JHipsterProperties; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.actuate.autoconfigure.MetricFilterAutoConfiguration; 
import org.springframework.boot.actuate.autoconfigure.MetricRepositoryAutoConfiguration; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; 
import org.springframework.boot.context.properties.EnableConfigurationProperties; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.core.env.Environment; 
import org.springframework.core.env.SimpleCommandLinePropertySource; 

import javax.annotation.PostConstruct; 
import javax.inject.Inject; 
import java.net.InetAddress; 
import java.net.UnknownHostException; 
import java.util.Arrays; 
import java.util.Collection; 

@ComponentScan 
@EnableAutoConfiguration(exclude = { MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class }) 
@EnableConfigurationProperties({ JHipsterProperties.class, LiquibaseProperties.class }) 
public class CrmScoringApp { 

    private static final Logger log = LoggerFactory.getLogger(CrmScoringApp.class); 

    @Inject 
    private Environment env; 

    /** 
    * Main method, used to run the application. 
    * 
    * @param args the command line arguments 
    * @throws UnknownHostException if the local host name could not be resolved into an address 
    */ 
    public static void main(String[] args) throws UnknownHostException { 
     SpringApplication app = new SpringApplication(CrmScoringApp.class); 
     SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args); 
     addDefaultProfile(app, source); 
     Environment env = app.run(args).getEnvironment(); 
    log.info("\n----------------------------------------------------------\n\t" + 
      "Application '{}' is running! Access URLs:\n\t" + 
      "Local: \t\thttp://127.0.0.1:{}\n\t" + 
      "External: \thttp://{}:{}\n----------------------------------------------------------", 
     env.getProperty("spring.application.name"), 
     env.getProperty("server.port"), 
     InetAddress.getLocalHost().getHostAddress(), 
     env.getProperty("server.port")); 
} 

/** 
* If no profile has been configured, set by default the "dev" profile. 
*/ 
private static void addDefaultProfile(SpringApplication app, SimpleCommandLinePropertySource source) { 
    if (!source.containsProperty("spring.profiles.active") && 
      !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) { 

     app.setAdditionalProfiles(Constants.SPRING_PROFILE_DEVELOPMENT); 
    } 
} 

/** 
* Initializes admin_panel. 
* <p> 
* Spring profiles can be configured with a program arguments --spring.profiles.active=your-active-profile 
* <p> 
* You can find more information on how profiles work with JHipster on <a href="http://jhipster.github.io/profiles/">http://jhipster.github.io/profiles/</a>. 
*/ 
@PostConstruct 
public void initApplication() { 
    if (env.getActiveProfiles().length == 0) { 
     log.warn("No Spring profile configured, running with default configuration"); 
    } else { 
     log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles())); 
     Collection<String> activeProfiles = Arrays.asList(env.getActiveProfiles()); 
     if (activeProfiles.contains(Constants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(Constants.SPRING_PROFILE_PRODUCTION)) { 
      log.error("You have misconfigured your application! " + 
       "It should not run with both the 'dev' and 'prod' profiles at the same time."); 
     } 
     if (activeProfiles.contains(Constants.SPRING_PROFILE_DEVELOPMENT) && activeProfiles.contains(Constants.SPRING_PROFILE_CLOUD)) { 
      log.error("You have misconfigured your application! " + 
       "It should not run with both the 'dev' and 'cloud' profiles at the same time."); 
      } 
     } 
    } 
} 

도시 저장소 클래스 : 여기

내 부팅 응용 프로그램의 클래스
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 30.66 sec <<< FAILURE! - in com.logate.adminpanel.web.rest.CityResourceIntTest 
firstTest(com.logate.adminpanel.web.rest.CityResourceIntTest) Time elapsed: 0.018 sec <<< ERROR! 
java.lang.IllegalStateException: Failed to load ApplicationContext 
     at  org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDeleg ate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) 
     at  org.springframework.test.context.support.DefaultTestContext.getApplication Context(DefaultTestContext.java:83) 
     at  org.springframework.test.context.support.DependencyInjectionTestExecutionL istener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) 
     at  org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) 
     at  org.springframework.test.context.TestContextManager.prepareTestInstance(Te stContextManager.java:228) 
     at  org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest (SpringJUnit4ClassRunner.java:230) 
     at  org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) 
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:249) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128) 
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) 
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) 

콘솔 오류 링크 : https://jpst.it/OJM6

누구 아이디어가 있습니까? 미리 감사드립니다.

+0

어떤 콩을 ''찾을 수 없습니까? – kjsebastian

+0

CityService 및 CityRepository –

+0

두 가지 질문을 모두 추가하여 편집 할 수 있습니까? 아니면 샘플 프로젝트를 github 같은 곳으로 업로드하십시오. – kjsebastian

답변

2

예외는 다음 원인으로 인해 발생합니다. java.lang.IllegalStateException: Tomcat connector in failed state. 일반적으로 Tomcat이 사용하는 포트가 이미 사용되고있을 때 발생합니다. server.portsrc/test/resources/config/application.yml 파일로 변경하십시오.

+0

나는 이것을 시도했지만 작동하지 않을 것이다. 예외가 throw됩니다. java.lang.IllegalStateException : ApplicationContext를로드하지 못했습니다. –

+0

프로젝트에서 jpa 저장소를 사용하도록 설정 했습니까? – eparvan

+0

오류 로그 전체 스택을 제공 할 수 있다면 도움이 될 것입니다 – eparvan

1

stackstrace에서 CityRestTest가 아니라 com.logate.adminpanel.web.rest.CityResourceIntTest 테스트에 실패했음을 알리고 있습니다. 당신이 당신의 테스트 gradle test에 사용할 수 있도록하려면

(인 당신이 CI/CD 시스템을 사용하는 경우 매우 권장), 클래스 이름은 "XXXIntTest"또는 "XXXUnitTest"를 포함하는 nameconvention을 따라야한다 ...

나는 CityResourceIntTest를 보았습니다. 실패가 있기 때문에 ... 나머지 테스트의 이름을 올바른 nameconvention으로 바꿉니다.

+0

수업 이름을 CityResourceIntTest로 변경했지만 질문에서 이름을 바꾸지 않았습니다. 오류는 다시 동일합니다. –

+0

CityResourceIntTest.firstTest»IllegalState가 ApplicationContext를로드하지 못했습니다. –

관련 문제