Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!

Sergei Prosvirnin

Greenhorn
+ Follow
since Nov 12, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sergei Prosvirnin


Hello, I hope I get my answer here regarding the Quartz API! In the Spring app_name.properties settings file, there is a line in cron format (e.g. 0 */1 * * * * ?) which defines how often to run a method in an inherited class. How do I get this string from the settings file in the executeInternal(JobExecutionContext jobExecutionContext) method not as a cron format, but the actual number of seconds, i.e. for the example above "60". I assume there is a ready method for such tasks in Quartz API.
2 weeks ago

Tim Holloway wrote:Well, for my JPA webapps, I have 3 layers: one for the raw database Entities, one for CRUD/finder operations on those entities (and in some cases, parent/child aggregates), and the highest layer is for business database service logic: graphs of entity relationships organised into working sets so that they can be detached and re-attached. The two logic layers: serice and DAO , I have marked as transactional, with the transaction context being inherited. That is to say, DAO operations made on behalf of a service function operate in the transaction of the service function.

A long-running and possibly failing operation such as HTTP is something that I would try very hard to deal with before invoking the service layer. That is. in the Business layer or perhaps a special layer between Business and Database Services. I would try to avoid making in transactional. If it has to be transactional, then you are entered the realm of XA transactions and that's a whole different can of worms and required a lot more transaction support than the basic JPA transaction system provides.



Thanks for the advice!
I am having some problems with Spring @Transactional and hope to find a solution here. I have a method in the service labeled as @Transactional which works by calling a method to request data via HTTP protocol (I'm using Apache HttpClient now), parsing the response and writing the result to the database. Since it all works in one method I'm afraid that this may cause transaction cancellation, because my project has a transaction time limit and request from external API may be really long.

Here I would like an answer on how to most correctly separate HTTP request+response parsing and database operations in such a case. As an option it is possible to have two methods one for transaction and the other for the rest of the logic, but I already have an assumption that there is a generally accepted design pattern for such tasks.

Tim Holloway wrote:Here's a general rule on how to work with the forum:

Ideally, someone should be able to pull up this page in 5 years or so (and people often do exactly that!), print it out on paper and be able to make sense of all the questions and answers. Editing in-place and offsite links both interfere with that ability.

Which is why we discourage them. It may be less efficient to do it the way we suggest, but sometimes efficiency isn't the goal.



Sorry about this mess.

I found a solution, instead of using these dependencies,



use this one.



In my case, Swagger is accessible via a URL - http://localhost:8080/api/swagger-ui/index.html
2 months ago

Tim Holloway wrote:I may be showing my blindness again, but I don't see dependencies for Springfox in your POM. But despite that, you seem to have a reference to it in your Maven repository cache. Is that the actual POM that you are using?



Sorry, I went crazy and took the file from the wrong branch. I updated the file.
2 months ago
This is the first time I can't get any version of swagger-fox up and running. Spring Boot 2.4.2 + JDK 8. I have previously added swagger-fox to my projects using the instruction below, but none fit.

Link on tuturial - https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

Run failed - https://pastebin.com/G34kGMc3


 

2 months ago

Mohammed Sardar. wrote:Could you confirm whether Controller & Service are placed in the same package where @SpringBootApplication class in placed ?

I faced this kind of issue once before.



Yes, but the classes are divided into separate sub-packages. I hope very much that I have a problem similar to you.

Dave Tolls wrote:If you want that service to be autowired in, then I'm pretty sure you have to annotate it as @Autowired.

Edit: that is, in the Controller.



Thank you, but I have already tried it.
Good afternoon! I'm new to Java please be patient. I want to get a list of entities via REST, but I can't link bean with service in MVC controller. Below is my code.

Repository


Service interface


Implementation of service interface



REST Controller


This code compiles, but when I call the curl controller I get a message that bin autocoupling has not happened and the object variable points to null.

Curl command


Message from the servlet container


Where is my mistake? Thanks to everyone who replies to this post!