小编rob*_*del的帖子

如何在测试之间重置

我有一个测试课

@RunWith(SpringRunner.class)
@DataJpaTest
Run Code Online (Sandbox Code Playgroud)

我有两个测试.在每个测试中我都做同样的操作,坚持对象.只有查找呼叫是不同的.

如果我同时运行两个测试,它们会失败但如果我一个接一个地运行测试它们就会成功.

每次测试之间没有重置.怎么做?在每个测试中,只有对存储库的调用是不同的.

@Test
public void findTopByCommerceCommerceIdOrderByEntryTimeDesc() {

    Long commerceId = 1L;

    Commerce commerce = new Commerce();
    commerce.setName("test");
    this.entityManager.persist(commerce);

    Member member = new Member();
    member.setCommerce(commerce);
    member.setMan(true);
    member.setName("bob binette");

    this.entityManager.persist(member);

    Visit visit1 = new Visit();
    visit1.setCommerce(commerce);

    visit1.setMember(member);
    visit1.setEntryTime(LocalDateTime.of(LocalDate.now(), LocalTime.now()));

    Visit visit2 = new Visit();
    visit2.setCommerce(commerce);

    visit2.setMember(member);
    visit2.setEntryTime(LocalDateTime.of(LocalDate.now().minusDays(2), LocalTime.now()));

    this.entityManager.persist(visit1);
    this.entityManager.persist(visit2);

    Visit visit = visitRepository.findTopByCommerceCommerceIdOrderByEntryTimeDesc(commerceId);

    assertEquals(visit.getVisitId(), Long.valueOf("1"));

}
Run Code Online (Sandbox Code Playgroud)

编辑

我把所有的代码:http://pastebin.com/M9w9hEYQ

java spring junit4 spring-data-jpa spring-boot

27
推荐指数
4
解决办法
1万
查看次数

如何使用spring boot和spring数据访问实体管理器

当我们使用spring boot和spring数据时,如何访问存储库中的实体管理器?

否则,我需要将我的大查询放在注释中,我宁愿有一些清楚的东西......然后是长文本.

spring-data spring-data-jpa spring-boot

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

失去了一天的约会

在客户端,我使用dd/MM/yyyy日期格式.该字段使用twitter bootstrap 3日期时间选择器(https://eonasdan.github.io/bootstrap-datetimepicker/)

我通过twitter bootstrap 3日期时间选择器24/07/2015
进入我发送的json,我看到:生日:"24/07/2015"

在我的dto,我做

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private Date birthdate;
Run Code Online (Sandbox Code Playgroud)

当我在服务器上收到日期时,在我的dto中看到:23/07/2015 19:00

有一天失去了.

任何解释?

java json jackson orika spring-restcontroller

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

@DataJpaTest需要在测试之外的类

在SpringBoot应用程序中,我想对存储库层进行一些测试.

@RunWith(SpringRunner.class)
@DataJpaTest
public class VisitRepositoryTest {

     @Autowired
     private TestEntityManager entityManager;

     @Autowired
     private VisitRepository visitRepository;

     ...
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行测试时VisitRepositoryTest,我收到一个错误DefaultConfigService

com.norc.Application中的字段defaultConfigService需要一个无法找到的类型为"com.norc.service.DefaultConfigService"的bean.

那么这需要运行Application吗?

我试着把豆子放进 DefaultConfigServiceVisitRepositoryTest,但是不允许这样做.

这个类在我的应用程序中使用

@EntityScan(basePackageClasses = {Application.class, Jsr310JpaConverters.class})
@SpringBootApplication
@EnableScheduling
public class Application implements SchedulingConfigurer {

      @Autowired
      private DefaultConfigService defaultConfigService;
      ...
}
Run Code Online (Sandbox Code Playgroud)

如何管理?


编辑

在我的应用程序中,我在cron选项卡中使用此类:

@Service
public class DefaultConfigServiceImpl implements DefaultConfigService {

    private final DefaultConfigRepository defaultConfigRepository;

    @Autowired
    public DefaultConfigServiceImpl(final DefaultConfigRepository defaultConfigRepository) {
         this.defaultConfigRepository = defaultConfigRepository;
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-test gradle spring-boot

12
推荐指数
1
解决办法
7590
查看次数

我做modprobe时找不到模块

我正在尝试安装此模块:https://github.com/mkottman/acpi_call

我做了一个make,make install.

然后我看到acpi_call.ko/lib/modules/4.3.3-5-default/extra/.

当我做的时候

modprobe acpi_call

我明白了

modprobe:致命错误:目录/lib/modules/4.3.3-5-default中找不到模块acpi_call

尝试投入acpi_call.ko,/lib/modules/4.3.3-5-default但得到相同的结果.

我想让它持久化,以便在我重新启动时加载模块.我认为只有modprobe才有可能.

linux linux-device-driver

8
推荐指数
1
解决办法
4万
查看次数

使用 git 推送到另一个分支

我通过 ssh 克隆了一个项目

git clone ssh ssh://git@10.7.5.11:IMER/ropolo.git
Run Code Online (Sandbox Code Playgroud)

master 分支受到保护,所以我不能推送我的更改。

还有另一个分支dev_ropolo

我需要把这个分支带到本地吗?需要做什么才能将我的更改推送到此分支?

编辑:

$ git fetch
* [new branch]      ropolo -> origin/ropolo

$ git branch
* master
Run Code Online (Sandbox Code Playgroud)

git

8
推荐指数
3
解决办法
4万
查看次数

Resttemplate 和补丁,无效

我使用弹簧 1.4.3

我尝试调用网络服务

  @PatchMapping(value = "/members/{memberId}/card")
  public ResponseEntity updateMemberCardId(@PathVariable("memberId") Long memberId, @RequestBody String cardId) throws ResourceNotFoundException {
        memberService.updateMemberCardId(cardId, memberId);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
  }
Run Code Online (Sandbox Code Playgroud)

在我的申请中,

@Component
@Configuration
public class ClientRestConfig {

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder, @Value("${main.server.url}") String mainServerUrl, @Value("${commerce.username}") String commerceUsername, @Value("${commerce.password}") String commercePassword,  @Value("${connection.timeout}") int timeout) {
        return builder.setConnectTimeout(timeout).setReadTimeout(timeout).basicAuthorization(commerceUsername, commercePassword).rootUri(mainServerUrl).build();
    }

}
Run Code Online (Sandbox Code Playgroud)

在另一种方法中我做

String cardId = "123456789";

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<>(cardId, headers);

ResponseEntity responseEntity =  restTemplate.patchForObject("/rest/members/1/card", entity, ResponseEntity.class);
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

java.net.ProtocolException: Invalid HTTP …

resttemplate spring-boot spring-restcontroller

7
推荐指数
2
解决办法
8410
查看次数

Hikari 和借用选项测试

我使用带有Hikari连接池、jpa 和 postgres 的spring boot 2 。

是否有任何理由继续使用这些选项

spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.testWhileIdle
Run Code Online (Sandbox Code Playgroud)

spring datasource apache-commons-dbcp spring-boot hikaricp

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

使用复合键保存实体获取 ConversionNotSupportedException

我使用 spring boot 2,我的一些实体有复合键

当我尝试保存实体时,出现此错误

无法转换请求元素:org.springframework.beans.ConversionNotSupportedException:无法将“java.lang.Integer”类型的属性值转换为属性“sampling”所需的类型“com.lcm.model.SamplingsPK”;嵌套异常是 java.lang.IllegalStateException:无法将“java.lang.Integer”类型的值转换为属性“采样”所需的类型“com.lcm.model.SamplingsPK”:找不到匹配的编辑器或转换策略

我用那个方法得到我的实体

public Samples findById(Integer id, int year, String sampleLetter) {
    Optional<Samples> optSamples = samplesRepository.findById(new SamplesPK(new SamplingsPK(year, id), sampleLetter));

    if (optSamples.isPresent()) {
        return optSamples.get();
    }

    return null;
}


Samples samples = samplesService.findById(idSeq, year, samplesLetter);

Compressions compressionTest = null;

if (samples.getTestSamples().getAbsorptionTest() != null) {
    compressionTest = samples.getTestSamples().getCompressionTest();
} else {
    compressionTest = new Compressions();
}

samplesService.save(samples);
Run Code Online (Sandbox Code Playgroud)

我的实体

@Entity
@IdClass(SamplesPK.class)
public class Samples extends BaseEntity{
    @Id
    private String sampleLetter;

    @Embedded
    private TestSamples testSamples;

    @Id
    @ManyToOne(optional=false)
    @JoinColumns({ …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa spring-data spring-data-jpa

6
推荐指数
2
解决办法
673
查看次数

无法部署,上下文文件已损坏

我使用tomcat 7和netbeans 7.4

当我启动我的Web应用程序时,我得到了

无法部署模块.context.xml文件似乎被破坏了.检查它是否格式良好且有效.该模块尚未部署.

这是我的context.xml文件

<?xml version='1.0' encoding='utf-8'?>
<Context>
    <Resource name="jdbc/shareDS" auth="Container" type="javax.sql.DataSource"
          maxActive="50" maxIdle="10" maxWait="100000"
          username="${db.user}" password="${db.password}" driverClassName="com.mysql.jdbc.Driver"
          url="${db.url}"
          timeBetweenEvictionRunsMillis="1800000" autoReconnect="true"
          removeAbandoned="true" removeAbandonedTimeout="300" logAbandoned="true"/>
</Context>
Run Code Online (Sandbox Code Playgroud)

当我尝试验证我的上下文文件时,我明白了

Cannot find the declaration of element 'Context'. [19] 
Run Code Online (Sandbox Code Playgroud)

任何的想法?

java tomcat netbeans

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