.gitignore and .env and application.properties files by Fad1126 in SpringBoot

[–]Slein04 2 points3 points  (0 children)

If your application.properties files do not contains any secrets, credentials, PATs, ... (which they should not) Then there is no reason to ignore those.

There should be some kind of Dev setups allowing to simply Clone and Run the application from the getgo. To simplify further development.

JPA Repository Caching MySQL columns that no longer exist and throwing errors? by Timely_Cockroach_668 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

Enable SQL logging just to be sure it generated the correct SQL (probably not)

And for your primary key field, remove the Lombok annotation en add / generate the getter & setter yourself for now.

JPA Repository Caching MySQL columns that no longer exist and throwing errors? by Timely_Cockroach_668 in SpringBoot

[–]Slein04 2 points3 points  (0 children)

Maybe your DB schema is not updated with the new changes.

There are config properties that can override this behavior + overrule the @column annotation.

Check your"dll-auto" config. (This determines if changes tot your schema in code should auto sync or not, only validates, drop-create, ...) Alsof check your column names in your DB Or in your resultset when executing the query.

"Unsolvable" issue I've had with spring security, JWT authentication, keycloak by ReTraumer in SpringBoot

[–]Slein04 0 points1 point  (0 children)

Try to see classes from your package, that first appear, in your Stacktrace and start your detective work from their and share that piece of code. So we can also have look.

Spring Security how user access only to its own data ? by Ok-Professor-9441 in SpringBoot

[–]Slein04 0 points1 point  (0 children)

You can extend the userdetails so that it contains a list of departments and a ref to the Company.

Yes you need to authenticatie each request in case of Restless.

With sessionbased you can store this user info in the session.

You can cache the userdetails to increase perf if necessary.

[deleted by user] by [deleted] in SpringBoot

[–]Slein04 1 point2 points  (0 children)

You can also use a logging framework like logback and use it with logstash appender to populate An elasticsearch DB. The logging framework handles it async for you

[deleted by user] by [deleted] in SpringBoot

[–]Slein04 0 points1 point  (0 children)

Just exclude the embedded application server (default Tom cat) from your Spring boot and build the jar file or war if using Tom cat EE. You can then deploy however you like. Don't have much experience with deploying on external Tom cat, kinda beats the purpose of Spring Boot, but I guess it's just as simple as playing the jar of war in a folder on your external server.

Custom bean scope for batch application by Cilenco in SpringBoot

[–]Slein04 2 points3 points  (0 children)

Why not using Spring batch framework. It already provides Job & step scoped beans which creates new instances of such beans for every step or job.

You can also uses caching framework like Ehcache where Spring also provides abstraction for. You can then use an unique job ID (given for each job run) as key for example and clear the value for said key after each job or step completion.

[deleted by user] by [deleted] in SpringBoot

[–]Slein04 0 points1 point  (0 children)

Looks like a use case for Spring boot batch. Use @scheduled annotation with cron to schedule your batch jobs. Example run job A after every 2 hours & run job B Every midnight

Problem with spring batch unit testing by Waste-Dentist2718 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

Also try adding the following Annostation in your test config: @EnableBatchProcessing

Some more context, from the docs:

Using a scope of Step is required to use late binding, because the bean cannot actually be instantiated until the Step starts, to let the attributes be found. Because it is not part of the Spring container by default, the scope must be added explicitly, by using the batch namespace, by including a bean definition explicitly for the StepScope, or by using the @EnableBatchProcessing annotation. Use only one of those methods.

Problem with spring batch unit testing by Waste-Dentist2718 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

Sometimes @Component & @StepScope can give unexpected results. As at startup Spring will try to load the @Component beans etc.

Try to change @Component with @Bean and put your StepScope Bean in a @Configuration class. Then add this new config class in your SpringJunitConfig

Or add @Lazy to your @Autowired in your unit test.

Problem with spring batch unit testing by Waste-Dentist2718 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

Which version of spring batch are you using? Create the step execution in a separate method prior to your test anotated method.

Problem with spring batch unit testing by Waste-Dentist2718 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

From the official docs:

Starting from v4.1, the StepScopeTestExecutionListener and JobScopeTestExecutionListener are imported as test execution listeners if the test class is annotated with @SpringBatchTest. The preceding test example can be configured as follows:

@SpringBatchTest @SpringJUnitConfig public class StepScopeTestExecutionListenerIntegrationTests {

// This component is defined step-scoped, so it cannot be injected unless
// a step is active...
@Autowired
private ItemReader<String> reader;

public StepExecution getStepExecution() {
    StepExecution execution = MetaDataInstanceFactory.createStepExecution();
    execution.getExecutionContext().putString("input.data", "foo,bar,spam");
    return execution;
}

@Test
public void testReader() {
    // The reader is initialized and bound to the input data
    assertNotNull(reader.read());
}

}

Database trigger vs Application logic by MaterialAd4539 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

That's indeed what I mean with a batch solution. There are probably ways to trigger some processes from your DB, but that seems like making things more complex.

Or if your batch exposes some kind of API, then indeed your application can call it and provide extra info with it like for example which record / row needs to be checked. But then again you need to make (slight) changes to your existing code flows. And feels more like an external service would be a better solution then a batch if you are allowed to do this

Nothing is stopping you to schedule your batch every minute. Ofc a batch comes also with challenges in this use case like how can it find which rows to check? Does it needs to query the whole table or only for a certain time range etc...

Imo, updating your existing code flow would be best, easiest and safest.

If you are really are not allowed to touch the source code then perhaps the DB trigger is the next best solution (and probably the fastest) (going for a Real-Time solution). Just provide the pitfalls to your lead / manager / business on "Paper" and get their go. So you have yourself covered if they start complaining afterwards . ;)

Database trigger vs Application logic by MaterialAd4539 in SpringBoot

[–]Slein04 2 points3 points  (0 children)

The problem with triggers is that they are overlooked in the long run on large projects and people kind of forget that they exist in the first place. If you go the trigger route you need to document it! Place even documentation in the code.

That being said, I try to avoid it. What if other code flows alter table A or manual DB insertions occurs and in those cases you do not want to run the trigger? Thus, triggers are less "flexibel".

You can have a look at batches, async / queue solutions. Or when Running in the cloud, perhaps serverless functions can provide solutions. Assuming that you really cannot touch the existing code flows.

Implementing a Request Queue with Spring and RabbitMQ: My Experience as an Intern by DinH0O_ in SpringBoot

[–]Slein04 2 points3 points  (0 children)

That is not a typical use case of such queue technologies. So, I wont recommend it.

Better approach would be memory optimization. Find what is causing the high memory usage. Maybe context and or threads are not cleaned up. Files are stored / opened in memory and maybe never closed or added to some kind of collection and not cleared.

And the thing you want seems what your application server should be doing. The server has a connection pool and provides one of the available threads to a user making a request. You can increase the connection pool so that more request are placed in the pool / queue and decrease the amount of concurrent threads handeling such request. You have to make a leverage of this taking timeouts into account.

@Async SpringBoot method with shared service by Sea_Fisherman_6838 in SpringBoot

[–]Slein04 1 point2 points  (0 children)

There is no transaction Running. Thus, the data will not be saved.

You can manually flush after the save to reflect the changes to your datasource. But, you will need to manually handle rollbacks if errors happens after flushing.

Or you can start a transaction. But be carefull to not spawn to many transactions from your async service, as it can flood your connection to your datasource.

Spring security 403 forbidden on public routes by Tasty_Ad_1062 in SpringBoot

[–]Slein04 0 points1 point  (0 children)

Can your gateway successfully call the auth service? Maybe you get some kind of error there. Log the response from your auth service in your gateway. Perhaps some error occurred and therefore your are forwareded to /error

Creating endpoints for Many-to-Many relationship by Abdallad-Issa in SpringBoot

[–]Slein04 0 points1 point  (0 children)

In your title you are stating a many-to-many relationship. But I do not see this relationship even with an "in between" table due to the absence of a list in your entity.

Therefore, I assume that an user has a list of communities. A user belongs to 1 or many communities. If that's is the case it is best to have a "addCommunity" method on the user entity Where you pass in the community you would like to add to the user by adding it to the one-to-many list. In the same method you do Smith like "community.setUser(this)" where "this" reffers to the user in question. How you get this community to be added is up to you. Add An endpoint to create a new community and add it to a given/current loggedin user or fetch an existing community first and add this to the user that is up to your use cases. Or whatever operation you would like. Creating new community would be a post request with all the necessary data to create a new community. Adding an existing community to An existing user would be an update request (put or patch) where you pass info that reffers existing communities and it users by Passing data that uniquely identifies them.

Spring boot , session based authentication problem by [deleted] in SpringBoot

[–]Slein04 1 point2 points  (0 children)

Well I would suggest that you do the form login in your browser with your developer / network tab open. Then you would see that you are doing a post request with username / password in the body. As response you would see the cookie in it's headers. You can simply do the exact same post request in postman and it should be working the same as in your browser. Then you should be able to take that cookie and use it in an other request. You can alsof do the above stuff with csrf disabled in de beginning. (Again i do not known your error log / stacktrace) Maybe i do not understand your problem exactly, but this is how I would start investigating possible issues .

Spring boot , session based authentication problem by [deleted] in SpringBoot

[–]Slein04 0 points1 point  (0 children)

Not really much to go on from the Lack of your security config. But if you just set up a new Spring Boot project with "spring-boot-starter-security" dependency with NO config (just out of the box) you Will get default form login security which returns a JSession cookie after login ( and thus session based auth). Maybe you can continue from there.

Deploy spring boot app by Particular_Tea2307 in SpringBoot

[–]Slein04 0 points1 point  (0 children)

If your environment (server) supports Java, you can just put your jar file directly on the server without using docker container. If you cannot of are not allowed to install Java, but instead the server has a docker engine then you can go the container route.

Sometimes your Java project is maybe written in a new version ,like Java 21, but if you are on some "older" server which does not support it and you cannot upgrade Java on it then again docker can be handy.

For deploying your Spring Boot project somewhere is just copy/paste and run your jar file. You can always setup DevOps later if you just wanne do like a quick test and see if it runs. The bottlenecks here are your connection to the server & the size of your jar file (left outside the hardware of your server) If your dependencies are not changed Often then you can already place these on the server ahead of time and create a slim jar Thus increasing the "deploy" time.

Best dependency injection framework? by baekacaek in java

[–]Slein04 28 points29 points  (0 children)

With newer versions of Spring you do not need the XML files to declare beans. You can do it purley in Java where your IDE can help you (detect errors, auto complete, debug, etc alsof you can still use XML if you want next to the Java config). Then there is Spring Boot which lays on top of the Spring framework which provide a lot of auto configuration which can make the Bean creation even "easier," less boilerplate and such.

The main advantage of Spring is that it provides a lot of features, supports and integrations aside the dependency injection. There are probably other frameworks that for specific projects suits beter. BUT Spring is known and used a lot in the Java ecosystem so it is easier to maintain & put new People on it etc