小编mak*_*son的帖子

无法加载ApplicationContext(带注释)

这是我的考试班.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
public class UserServiceImplIT {

    @Autowired
    private SampleService sampleService; 

    @BeforeClass
    public static void setUp() {
        System.out.println("-----> SETUP <-----");
    }

    @Test
    public void testSampleService() {
        assertTrue(true);
    }
}      
Run Code Online (Sandbox Code Playgroud)

异常(许多例外,主营: Failed to load ApplicationContext,
Error creating bean with name 'defaultServletHandlerMapping'.
Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception;,
A ServletContext is required to configure default servlet handling )

java.lang.IllegalStateException:无法在org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)在org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java加载的ApplicationContext: 83)在在org.springframework.test org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)在org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) .context.TestContextManager.prepareTestInstance(TestContextManager.java:228)org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230)org.springframework.test.context.junit4.SpringJUnit4ClassRunner $ 1.runReflectiveCall( SpringJUnit4ClassRunner.java:289)org.junit.internal.runners.m odel.ReflectiveCallable.run(ReflectiveCallable.java:12)org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner. java:249)org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)org.junit.runners.在org.junit的org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58)的org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)中的ParentRunner …

junit spring spring-mvc spring-security

12
推荐指数
3
解决办法
7万
查看次数

在Jenkinsfile中的步骤中找不到这样的DSL方法

我想在循环中执行一些阶段.我有Jenkinsfile

pipeline {
  agent any
  tools {}
  parameters {}
  environment {}
  stages {
    stage('Execute') {
      steps {
        script {
          for (int i = 0; i < hostnameMap.size; i++) {

            hostname = hostnameMap[i]
            echo 'Executing ' + hostname

            stage('Backup previous build ' + hostname) {
              backup(hostname, env.appHome)
            }


            stage('Deploy ' + hostname) {
              when {
                expression { env.BRANCH_NAME ==~ /(dev|master)/ }
              }
              steps {
                script {
                  deploy(hostname , env.appHome, env.appName)
                }
              }
            }

            stage('Restart ' + hostname) {
              when {
                expression …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-pipeline

7
推荐指数
1
解决办法
7597
查看次数

我如何从 crudrepository 获取 entitymanager

我使用 Spring Boot 并希望提高性能。我必须在数据库中下载 50000 字段的文件。使用休眠。我在Batch inserts 中找到了解决方案。但我不知道如何从 crudrepository 获取 entitymanager

public interface MyRepository extends CrudRepository<OTA, Long>

application.yaml
                jdbc.batch_size: 50
                order_inserts: true
                order_updates: true
                cache.use_second_level_cache: true
Run Code Online (Sandbox Code Playgroud)

我创建了 MyStorageService 并想保存我的文件:

@Service @Repository @Transactional public class MyStorageService {
    private MyRepository myRepository;

    private void insertAll(final List<MyFile> file) {
        myRepository.save(file.getListLine());
    } 

private void insert(final List<OTA> ota) {
    Session session = (Session) entityManager.getDelegate();

    Transaction tx = session.beginTransaction();

    for (int i = 0; i < ota.size(); i++) {
        session.save(ota.get(i));
        if (i % 50 == …
Run Code Online (Sandbox Code Playgroud)

hibernate spring-data spring-boot

5
推荐指数
1
解决办法
6974
查看次数

春季启动2(版本2.0.0.M7)中不能包含Prometheus指标

在spring boot 2(版本2.0.0.M7)项目中不能包含Prometheus指标.

微米文档添加弹簧引导起动器的依赖,并在application.yaml加入management.endpoints.web.expose:普罗米修斯,但是打电话时/执行器/普罗米修斯 GET
{ "timestamp": 1518159066052, "path": "/actuator/prometheus", "message": "Response status 404 with reason \"No matching handler\"", "status": 404, "error": "Not Found" }

请告诉我为什么我没有获得prometheus指标?

metrics spring-boot prometheus

3
推荐指数
3
解决办法
5989
查看次数

如何在内容类型 application/x-www-form-urlencoded 中使用自定义对象测试 Post 请求?

我有控制器:

    @PostMapping(value = "/value/", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public String updateSettings(final Dto dto) {
        System.out.println(">>> " + dto);
        return "template";
    }
Run Code Online (Sandbox Code Playgroud)

如果我通过 Chrome 窗口发送请求,控制器就会工作。但是当我为这种方法编写测试时,我遇到了问题。未转换的对象,未插入值。

测试:

@Test
    @WithMockUser(username = FAKE_VALID_USER, password = FAKE_VALID_PASSWORD)
    public void test_B_CreateDtoWithValidForm() throws Exception {

        final Dto dto = new Dto();
               dto.setId("value");
               dto.setEnabled("true");

        this.mockMvc.perform(post(URL_SET_PROVIDER_SETTINGS)
                .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE)
                .content(dto.toString()))
                    .andDo(print());
  }
Run Code Online (Sandbox Code Playgroud)

输出是 >>> Dto{id=null,enabled=false}

如何在内容类型 application/x-www-form-urlencoded 中使用自定义对象测试 Post 请求?

spring-test-mvc spring-boot mockmvc

2
推荐指数
1
解决办法
5889
查看次数