I have created a Spring Boot Web Application with Hibernate. I am using Microsoft Azure and SQL Database to deploy my application. I have configured the database on Azure and in my code. Configuration code is- 1. application.properties file 2. application.yml file I am creating several tables in my database. All the tables are getting created, but one that needs
Tag: spring-boot
Spring Batch: KafkaItemReader reads from offset 0 if the JVM is not restarted
I’m trying to implement a Spring Batch job that is scheduled by a Spring scheduler. The current befavior is as follows: The job is launched by the scheduler using JarLauncher The job consumes the kafka records and processed them The next time the jobs ris launched by the scheduler, it consumes the kafka records already processed The expected behavior is
Should Spring Boot Data JPA automatically create EntityManagerFactory bean?
Should Spring Boot Data JPA automatically create EntityManagerFactory bean? I have added a table using Liquibase called Fred to my code, and now I wish to add JPA support for this. Upon adding: I get I understood that this bean should be created by spring. Can anyone explain when spring creates this bean for me? If it doesn’t, why not?
Fail to generate allure-results directory based on JUnit 4
I failed to generate the directory allure-results in my project. I have tried many methods from google(create src/test/resources/allure.properties, set <resultsDirectory>${project.build.directory}/allure-results</resultsDirectory> in pom.xml, etc.), but all setting seems not to take effect. I also failed to redirect the result to other directories. It always said “[ERROR] Directory <project_path>/target/allure-results not found”. My command to generate report is My pom.xml is like: Answer
Spring jpa database connection for native query
I have a spring application that have to connect to a sql server db. There are no @Entity class and there ate no @Repository because the tables and the columns of the tables are unknown to the application. I have created a class and used an entity manager to execute queries, but I’m not sure this is the best choice
How to access configuration beans in Spring controllers
I have a Spring Boot application that uses Spring profiles to create environment specific configurations, for example: I have a @RestContoller that needs to access the values that the configurations load from application.properties. How can I inject the current environment specific configuration bean inside the controller? Example: Answer If you need to access values from the application.properties or .yaml configuration
delete where all keys of a map are contained in a list in mongodb
I have this: A field which is a map where the keys are UUIDs and the value another object which is not relevant. A list of UUIDs that should be passed as parameter. I want to: delete from the collection all documents where all keys of the map are included in the list of UUIDs The object: With derived queries
type=search_phase_execution_exception, reason=all shards failed when i send ‘/’
I’m using elasticSearch with RestHighLevelClient and Java. When I put query: QueryBuilder qb = new QueryStringQueryBuilder(“” + valueSearch.toLowerCase() + “”). Where valueSearch contain “/” -> example REC2/. The searchResponse = client.search(searchRequest, RequestOptions.DEFAULT) return me Caused by: org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]. However, when I send Rec2/2/3 or Rec// everything its ok. Version elastic: 7.3.0 Answer The query_string query
are there any pitfalls when return @Entity from @RestController instead of DTO?
are there any pitfalls when return @Entity from @RestController instead of DTO ? like this: Answer I’d say yes. By returning an entity, you are going to have tight coupling of your response contract and the database entity. So in future if you want to make modifications to either your response/entity, you might run into multiple issues. For example, let’s
Is CSRF token require for Rest API in Spring boot
I am creating a Rest API using Spring boot on back-end and React js on frontend . I have a login form on React , should I enable csrf token on login/register form or not . After user logs in that user will get access token which I will store in memory in React and Refresh token in http only