Mock external server during integration testing with Spring

After playing a bit with various scenarios, here is the one way how can one achieve what was asked with minimal interventions to the main code Refactor your controller to use a parameter for thirdparty server address: @RestController public class HelloController { @Value(“${api_host}”) private String apiHost; @RequestMapping(“/hello_to_facebook”) public String hello_to_facebook() { // Ask facebook about … Read more

Spring JPA Repository dynamic query [duplicate]

Per JB Nizet and the spring-data documentation, you should use a custom interface + repository implementation. Create an interface with the method: public interface MyEntityRepositoryCustom { List<User> findByFilterText(Set<String> words); } Create an implementation: @Repository public class MyEntityRepositoryImpl implements MyEntityRepositoryCustom { @PersistenceContext private EntityManager entityManager; public List<User> findByFilterText(Set<String> words) { // implementation below } } Extend … Read more

Not annotated parameter overrides @??? parameter

Explanation Although I can’t reproduce this on AbstractItemCountingItemStreamItemReader from this artifact implementation group: ‘org.springframework.batch’, name: ‘spring-batch-core’, version: ‘4.1.2.RELEASE’ , this annotation means that the parent method has some @NotNull / @NonNull annotation on the parameter, while the overriding method has no. To fix it, you need to put the same annotation on the overriding method. … Read more

Deploy Spring Boot to Tomcat

The chapter Packaging executable jar and war files in the Spring Boot reference documentation states: To build a war file that is both executable and deployable into an external container you need to mark the embedded container dependencies as “provided”, e.g: <?xml version=”1.0″ encoding=”UTF-8″?> <project xmlns=”http://maven.apache.org/POM/4.0.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”> <!– … –> <packaging>war</packaging> <!– … … Read more

Configure Spring Boot with two ports

As is has been mentioned before, server.port and management.port along with management.context-path properties could be set to make the embedded container to listen on different ports (management-related properties to access Actuator endpoints). To listen on ports other than server.port and management.port: @Configuration public class EmbeddedTomcatConfiguration { @Value(“${server.additionalPorts}”) private String additionalPorts; @Bean public EmbeddedServletContainerFactory servletContainer() { … Read more

No qualifying bean of type [javax.persistence.EntityManager]

The EntityManager interface belongs to JPA and is implemented by JPA providers (such as Eclipse), not Spring, and it has its own injection annotation: @PersistenceContext. EntityManager objects are transaction-scoped and should not be exposed as beans as you’re doing. Instead, either use the JPA annotation to inject the EntityManager: @PersistenceContext EntityManager em; or, since it … Read more

No validator could be found for constraint ‘javax.validation.constraints.Size’

@Size is a Bean Validation annotation that validates that the associated String has a value whose length is bounded by the minimum and maximum values. And as your exception says it does not apply to Integer type. Use: @Range @Column(name= “discount_percentage”) @Range(min=0, max=90) private Integer discountPercentage = 0; Or you cloud also use only @Max … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)