Java Community | Help. Code. Learn.

JCH

Java Community | Help. Code. Learn.

With more than 20,000 members, join one of the biggest and most active Java Communities on Discord! ☕

Join

java-help

❓︱qotw-answers

Spring Security

I am Not Able to Access Any Of my Endpoints here is the Config File ```package com.example.firstSpringBoot.config; import java.util.ArrayList; import java.util.List; ...
No description

how to manage two ssl certs in my spring app?

hey guys. i have mTLS in my app. i have jks with two certs in it. cert1 and cert2. my app calls two completely different apis/endpoints: api1/endpoint1 and uses cert1, and api2/endpoint2 and uses cert2. i was wondering do i need to make any changes in my rest template config? bc as i understand, i need to specify which cert to use for which api (or endpoint). but i was told that when mTLS is being initated and my app receives CertificateRequest, spring looks into the keystore, and just...

Spring Security

I dont know why but i am not getting default login page after enabling the @WebSecurity annoation .. ```package secuityConfig; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;...
No description

Spiring bean scope related query

okay so i was just making a mini project where the first page is a login page and when you login successfully youll get a page where you can add items to your cart and also option to display your cart i made a session mapped LoginService class which has a private User attribute so whenever there was a succesful login i was assigning the user attribute of LoginService an object(the first function) and whenever an item was to be added i was adding it to the user attribute of LoginService bean(second method) but different LoginService beans are injected into the first and second method. Why is that so. isnt LoginService SessionMapped??...

how to use two separate SSL certs when my app calls different endpoints?

hey guys. i have a spring application. there are two endpoints that are being called in it (for example endpoint1 and endpoint2). and also there are two security certificates (for example cretificate1 for endpoint1 and certificate2 for endpoint2). i have a problem. how to switch between certificates? because once the application is running, the JKS is already loaded. how to approach this issue? thanks in advance.

jackson json question

suppose i have json array stored inside the file in the projects variable. how can i update it properly without rewriting it?...
No description

couldnt resolve placeholder from the config

hey guys. i have this config: ```yaml bankAccounts: - iban: "LT123" cashRegId: 2...

how to use resource in resourceloader?

hey guys. i have an xml in this dir: src/main/resources/communicationTestRequestBody.xml and i dont know how to specify the dir: ```java ResourceLoader resourceLoader = new DefaultResourceLoader();...

Gradle Translation

What is the gradle equivalent of this?
mvn org.apache.maven.plugins:maven-install-plugin:3.1.2:install-file -Dfile=LocalDependency.jar
mvn install
mvn org.apache.maven.plugins:maven-install-plugin:3.1.2:install-file -Dfile=LocalDependency.jar
mvn install
...

better ways to load xml as a string?

hey guys. i want to load xml as a string. im doing it this way:
String requestBodyTemplate = new String(Files.readAllBytes(Paths.get("src/main/resources/accountStatementRequestBodyTemplate.xml")));
String requestBodyTemplate = new String(Files.readAllBytes(Paths.get("src/main/resources/accountStatementRequestBodyTemplate.xml")));
and some people on the internet told me there are better ways, but they didnt explain to me. can smb help me out? thanks...

Java Rest API

Can Anyone Explain is it really necessary to make a Rest Api while Storing the user's in the db from registering page ? And when do we actually use a Rest Api in our web application ?

Force install dependency.

I have a maven project with a dependency in the pom: ```xml <dependency> <groupId>tld.domain1</groupId>...

Update Error In Spring MVC

I am Trying to update the user But i found the 405 error like this https://sourceb.in/k8YQbPRuTj why i am getting this Please Help...

Spring JDBC

I am Getting a error like this https://sourceb.in/IQyZlhnarV when i am trying to retrive the id from the table Can Someone Help please...

onMouseClicked event doesnt do anything

<Pane onMouseClicked="#selectPath" style="-fx-border-color: red" AnchorPane.topAnchor="4" AnchorPane.rightAnchor="4" AnchorPane.bottomAnchor="4">
<JetBrainsImage pickOnBounds="true" icon="AllIcons.Expui.General.Open" />
</Pane>
<Pane onMouseClicked="#selectPath" style="-fx-border-color: red" AnchorPane.topAnchor="4" AnchorPane.rightAnchor="4" AnchorPane.bottomAnchor="4">
<JetBrainsImage pickOnBounds="true" icon="AllIcons.Expui.General.Open" />
</Pane>
...

Gradle shade not shading in one operating system, but does in another

I made a docker container meant to build all my paper plugins (minecraft server). The problem is that by somre reason, it does not shade what is otherwise being shade when I run the same command in my OS (windows) Does anyone have a clue what would be the case? I'm quite new to gradle, so that might be the cause. Here's part of the build script: ```kts shadowJar {...

Spring MVC

Whenever I Click on the
profile
profile
endpoint then my console is starting printing the image of the user in binary format that cause alot of lagging and stopping my program. Please Help. https://srcb.in/wGaSDYunV1p...

How to access authenticated user/authentication object on react frontend after logging in?

I've set up a basic authentication flow using Spring Security 6 on my backend, with React handling the frontend for login, signup, and verification pages. It's all session cookie-based, no JWT, with sessions stored in Redis. Now, I'm wondering how I can handle things on the React side once a user logs in. How do I check if a user is logged in to restrict access to certain pages? I want to redirect them to the login page if they're not logged in or restrict page access based on their roles. Any tips on how to manage this? I also want to be able to get access to the authenticated user's details like their email, username, etc unless this isn't possible without implementing a /me endpoint on the backend that fetches the user details for me....

Implementing Desmos Function into Java

I've got a function in desmos and want to convert it into java, but I can't figure out how I would put this:
No description

I cant figure out how to rename a file.

in order to delete from a file I first need to write everything that I don't want to delete into another file and then rename the the new file to the name of the old file. Then I would delete the old file. This is represented in the getDate() method. I am noticing that the new file (temp.txt) refuses to be renamed to the old file (savedata.txt). What should I do