小编Mac*_*zuk的帖子

使用junit test将命令行参数传递给Spring Boot应用程序

我有一个非常基本的Spring Boot应用程序,它期望来自命令行的参数,并且没有它不起作用.这是代码.

@SpringBootApplication
public class Application implements CommandLineRunner {

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

    @Autowired
    private Reader reader;

    @Autowired
    private Writer writer;

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

    @Override
    public void run(String... args) throws Exception {

        Assert.notEmpty(args);

        List<> cities = reader.get("Berlin");
         writer.write(cities);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的JUnit测试类.

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

    @Test
    public void contextLoads() {
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,Assert.notEmpty()要求传递一个论点.但是,现在,我正在编写JUnit测试.但是,我得到了以下异常加注Assert.

2016-08-25 16:59:38.714 ERROR 9734 --- [           main] o.s.boot.SpringApplication               : Application startup failed …
Run Code Online (Sandbox Code Playgroud)

java junit spring unit-testing spring-boot

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

带有Spring Boot的SPA - 为非API请求提供index.html

我目前正在开发一个应该使用单页React前端的网页.对于后端,我正在使用spring boot框架.

所有api调用都应使用前缀为url的URL,/api并应由REST控制器处理.

所有其他网址应该只是提供index.html文件.如何用弹簧实现这一目标?

spring spring-mvc single-page-application spring-boot

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

具有规范、分页和标准的 Spring Data JPA 存储库

我正在为实体列表实现搜索/过滤服务,使用具有规范和分页功能的 Spring Data JPA 存储库。我正在尝试减少查询次数(n+1 问题)并使用标准获取机制获取嵌套数据。

我有两个实体类:

@Entity
@Table(name = "delegations")
public class Delegation {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    @ManyToOne
    private Customer customer;

    // more fields, getters, setters, business logic...

}
Run Code Online (Sandbox Code Playgroud)

@Entity
@Table(name = "customers")
public class Customer {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    private Long id;

    // more fields, getters, setters, business logic...
}
Run Code Online (Sandbox Code Playgroud)

DTO过滤器类:

public class DelegationFilter {

    private String customerName;

    // more filters, getters, setters...
}
Run Code Online (Sandbox Code Playgroud)

和搜索/过滤服务:

public class DelegationService {
    public Page<Delegation> findAll(DelegationFilter …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-data spring-data-jpa

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