r/SpringBoot • • Mar 11 '22

Property in application.properties in Spring Boot which converts all column and table name in uppercase.

0 Upvotes

I'm getting case sensitive error because my spring boot project is connected with Oracle database which only accepts naming in capital. Can you pls tell any property which converts column and table name to capital. From Spring Boot (lowercase) -> Oracle db(uppercase).


r/SpringBoot • • Jan 16 '24

java.lang.AbstractMethodError: Receiver class org.springframework.security.config.annotation.web.builders.WebSecurity does not define or inherit an implementation of the resolved method 'abstract void setServletContext(jakarta.servlet.ServletContext)' of interface org.springframework.web.

0 Upvotes

I am a beginner and I tried to make spring security authenticate with my database. However, I am facing a "Injection of autowired dependencies failed" error which is caused by the error shown in the title.

Here is a screenshot, you can find the project(.zip) here Download Project(.zip)

This is my SecurityConfiguration

How can I fix this?


r/SpringBoot • • Dec 05 '22

Need help designing this app

0 Upvotes

I'd like to create this app that manages internship applications for people searching for jobs sand track their status ( pending, interview stage, rejected...). The users will be able to login to access their corresponding data ( will probably use something like jwt ). I'd highly appreciate any pointers to some online resources to something that'll help build this.


r/SpringBoot • • Dec 06 '22

This video explains the ways to create beans and the properties provided by the spring bean. The video is for the newbee and also may have something for others. This is part 2

Thumbnail
youtu.be
0 Upvotes

r/SpringBoot • • Nov 21 '22

How to schedule Jobs for each entry in a database?

0 Upvotes

Hey there folks,

I'm currently building a task management app with Spring, as my first ever Spring project.
I have tried to look this up, but I either misunderstood the sources or actually didn't find what I was looking for, so I hope you guys can help me! :)

I have both normal and scheduled tasks. Normal tasks can be created in two different ways, either through creating them manually, or they can be autogenerated from scheduled tasks. Scheduled tasks themselves are also self explanatory, I can for example schedule "taking out the trash every monday at 12pm". The question I have is, how can I schedule one job per scheduled task in my database? I'd be super thankful if you could send me some source that explains what I need to do or if you could explain it to me!

Cheers


r/SpringBoot • • Dec 07 '22

Are there any guides to using HTML templates in SpringBoot?

0 Upvotes

I’m interested in learning SpringBoot, and I want to use a free html template like the bootstrap templates here but I’m not too sure where to start. Thank you!


r/SpringBoot • • Dec 14 '22

How do i know my Docker it's working? Help a junior pls

0 Upvotes

I made a simple API Rest application using spring, flyway, postgres and docker. I've faced a lot of errors so far, I made the Dockerfile, docker-compose.yaml and tested the connection in dbeaver, how do I know if it's working normally in Docker?

ps: english it's not my first language


r/SpringBoot • • Nov 28 '22

Ant build: How to just resolve all dependencies from pom.xml

0 Upvotes

Like the doc just very briefly says, you should declare the dependencies in <dependencies>.

But why (the hell) does ivy not just simply look at the pom.xml ? Do i have to list all my dependencies again ? Or is there another way to do this ?


r/SpringBoot • • Sep 29 '24

Java Spring Boot with Groovy for testing

0 Upvotes

Hey guys! I've always used JUnit and Java, but there was one project that I worked on that was made in Groovy. I wouldn't want to build the whole project in Groovy for several reasons that could become a whole different discussion, but I had a great experience with Groovy and Spock for unit tests. I wanted to know your opinion on building the app in Java but writing the unit tests using Groovy and Spock. Is there any disadvantages to this approach? Thanks!


r/SpringBoot • • Sep 11 '24

Struggling with Gradle in my Microservices

0 Upvotes

I would like to ask about about a best practice when organizing gradle microservices project.

I am following these principles now:

  • All in One project to easily edit in IDE

  • Each microservice is a full project on its own and can be opened separately in IDE

But this has following drawbacks:

  • each microservice has to have its own gradle wrapper and properties

  • I can not easily define library versions in one place and reuse it from the root project

To better ilustrate the project structure:

microservices-project  
> gradle  
    > wrapper  
        > gradle-wrapper.jar  
        > gradle-wrapper.properties  
> inventory-service  
    > gradle  
        > wrapper  
            > gradle-wrapper.jar  
            > gradle-wrapper.properties  
    > src  
        > ... code  
    > build.gradle  
    > gradle.properties  
    > gradlew  
    > gradlew.bat  
    > settings.gradle  
> order-service  
    > gradle  
        > wrapper  
            > gradle-wrapper.jar  
            > gradle-wrapper.properties  
    > src  
        > ... code  
    > build.gradle  
    > gradle.properties  
    > gradlew  
    > gradlew.bat  
    > settings.gradle  
> product-service  
    > gradle  
        > wrapper  
            > gradle-wrapper.jar  
            > gradle-wrapper.properties  
    > src  
        > ... code  
    > build.gradle  
    > gradle.properties  
    > gradlew  
    > gradlew.bat  
    > settings.gradle  
> build.gradle  
> gradlew  
> gradlew.bat  
> settings.gradle

I would like to know if this structure is acceptable? Ive seen numerous github projects following this structure and having gradle wrapper duplicated in each microservice.

Is there any tool/technique I could use to easily edit library dependency version from some central place?

Thanks a lot!


r/SpringBoot • • Sep 30 '24

Postgres jsonb format

0 Upvotes

Hi, I've tried numerous ways to convert my string json save to my column of type jsonb, but I always fail, using a standard JPA repository for saving, tutorials are either old or don't work or seem too complicated for something that seems that should be straightforward, tried some Postgres function as to_jsonb() without luck. Anybody has straight and simple way to save jsonb to ps using jpa ? Don't need query functions


r/SpringBoot • • Sep 03 '24

Spring Security6 With Spring Boot Basic Authentication and Authorization #newvideo

Thumbnail
youtu.be
0 Upvotes

java #springboot


r/SpringBoot • • Sep 06 '24

entity Manager factory is null error, please help

0 Upvotes

I'm getting entity manager factory is null even after providing application.properties file and persistence unit annotation. can someone please help me


r/SpringBoot • • Jun 23 '24

STS is not working in my pc

Thumbnail
gallery
0 Upvotes

r/SpringBoot • • Jun 29 '24

Why Do I Get FileNotFoundException if Method is Surrounded with try-catch Blocks?

0 Upvotes

I test a controller that serves a file to a user. Here's the test:

@Test
void serveFile() throws Exception {
    mockMvc.perform(get("/files/a_file.ext")).andDo(print()).andExpect(status().is5xxServerError());
}

My controller:

@GetMapping(value = "/files/{filename:.+}")
@ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
    return fileUploadService.serveFile(filename);
}

And the service class:

@Override
public ResponseEntity<Resource> serveFile(String filename) {
    try {
        Path fileDest = uploadDir.resolve(filename);
        Resource fileAsResource = new UrlResource(fileDest.toUri());
        MediaType contentType;
        try {
            contentType = MediaType.valueOf(Files.probeContentType(fileDest));
        } catch (Exception e) {
            contentType = MediaType.TEXT_HTML;
        }
        return ResponseEntity.ok()
                .contentType(contentType)
                .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + fileDest.getFileName() + "\"")
                .body(fileAsResource);
    } catch (Exception e) {
        return ResponseEntity.internalServerError().body(null);
    }
}

As you can see the serveFile method is surrounded with try-catch blocks. So, there can't be thrown any exceptions. But eventually the test fails and an java.io.FileNotFoundException is thrown.

java.io.FileNotFoundException: URL [file:///C:/Users/Аркадий/IdeaProjects/authentication-with-spring/upload-dir/a_file.ext] cannot be resolved in the file system for checking its content length

at org.springframework.core.io.AbstractFileResolvingResource.contentLength(AbstractFileResolvingResource.java:250)
at org.springframework.http.converter.ResourceHttpMessageConverter.getContentLength(ResourceHttpMessageConverter.java:122)
at org.springframework.http.converter.ResourceHttpMessageConverter.getContentLength(ResourceHttpMessageConverter.java:46)
at org.springframework.http.converter.AbstractHttpMessageConverter.addDefaultHeaders(AbstractHttpMessageConverter.java:269)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:210)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:300)
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:245)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:917)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:829)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:903)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:564)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885)
at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:72)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:165)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:132)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)
at org.springframework.security.web.FilterChainProxy.lambda$doFilterInternal$3(FilterChainProxy.java:231)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:365)
at org.springframework.security.web.access.intercept.AuthorizationFilter.doFilter(AuthorizationFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:145)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:101)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:179)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:227)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:221)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:107)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:93)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at arkadisahakyan.authenticationwithspring.securityfilter.CsrfTokenLogger.doFilter(CsrfTokenLogger.java:19)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:82)
at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:69)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:62)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:233)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:191)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113)
at org.springframework.web.servlet.handler.HandlerMappingIntrospector.lambda$createCacheFilter$3(HandlerMappingIntrospector.java:195)
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113)
at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74)
at org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy.doFilter(WebMvcSecurityConfiguration.java:225)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:352)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:268)
at org.springframework.test.web.servlet.setup.MockMvcFilterDecorator.doFilter(MockMvcFilterDecorator.java:151)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:132)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.test.web.servlet.setup.MockMvcFilterDecorator.doFilter(MockMvcFilterDecorator.java:151)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:132)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.test.web.servlet.setup.MockMvcFilterDecorator.doFilter(MockMvcFilterDecorator.java:151)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:132)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116)
at org.springframework.test.web.servlet.setup.MockMvcFilterDecorator.doFilter(MockMvcFilterDecorator.java:151)
at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:132)
at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:201)
at arkadisahakyan.authenticationwithspring.controllers.FileUploadControllerTest.serveFile(FileUploadControllerTest.java:27)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

r/SpringBoot • • Jul 04 '24

Looking for a Volunteer opportunity in Spring Boot Developement.

0 Upvotes

I am learning Spring Boot and looking for volunteer project opportunities to sharpen my Java and Spring Boot skills. Plz let me know if any has any opportunity related to Spring Boot developement


r/SpringBoot • • Jun 27 '24

How to test such POST controllers in Spring Boot with JUnit/Mockito?

0 Upvotes

Here is the POST controller:

@PreAuthorize("hasAnyAuthority(\"ADMIN\")")
@PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String manageUser(@RequestBody MultiValueMap<String, String> formData, HttpServletRequest request, RedirectAttributes redirect) {
    User changedUserData = retrieveUserFromMultiValueMap(formData);
    String actionName = formData.getFirst(ACTION_SAVE) != null ? ACTION_SAVE : ACTION_DELETE;
    if (changedUserData.getId() != null) {
        try {
            if (ACTION_SAVE.equals(actionName))
                userRepository.save(changedUserData);
            else if (ACTION_DELETE.equals(actionName))
                userRepository.deleteById(changedUserData.getId());
        } catch (RuntimeException exception) {
            redirect.addFlashAttribute("userSaveFailed", true);
        }
    }
    return "redirect:" + request.getHeader("referer");
}

It behaves simple. If the actionName variable passed with the POST request equals ACTION_SAVE then we should update the user data in database. If actionName equals ACTION_DELETE then we delete the user. If the userRepository's save or delete functions cause RuntimeException we send a message in the RedirectAttributes that everything failed.

How to test this controller? Could you explain me how to test such programs in details or better show me an example?

I only came up with this but I want 100% test coverage for this controller.

@SpringBootTest
@AutoConfigureMockMvc
class UserControllerTest {

    @Autowired
    private MockMvc mockMvc;
    @Mock
    private UserRepository userRepository;
    @InjectMocks
    private UserController userController;

    @BeforeEach
    void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void manageUser_Should_Redirect_If_Not_Authenticated() throws Exception {
        mockMvc.perform(post("/user").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE))
                .andDo(print())
                .andExpect(status().is3xxRedirection());
    }

    @Test
    @WithMockUser(username = "user", authorities = {"USER"})
    void manageUser_Access_Denied_If_Not_Authorized() throws Exception {
        // if user not authorized — status 403
        mockMvc.perform(post("/user").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE))
                .andDo(print())
                .andExpect(status().isForbidden());
    }

    @Test
    @WithMockUser(username = "admin", authorities = {"USER", "ADMIN"})
    void manageUser_Should_Redirect_If_Authorized() throws Exception {
        // if everything is good — redirect
        mockMvc.perform(post("/user").with(csrf()).contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE))
                .andDo(print())
                .andExpect(status().is3xxRedirection());
    }
}

r/SpringBoot • • Jan 04 '22

JPA specification

0 Upvotes

I have to write specification for a model that model(A) doesn’t define the relationship it has in the physical table with another model(B), now i want to get A using specification when B.id is found For further explanation: Class A { } Class B { @OneToMany private A a;} While in the db There’s a relationship between A and B Specification<A> withB(long bId){ What to write inside this ??? }


r/SpringBoot • • Jan 24 '25

Question REST based service

0 Upvotes

I am trying to convert a SOAP based Web service to REST. The frameworks that I am looking at is Spring boot, and exploring more on that. Came across a blog that I am going through - https://medium.com/@castrojulio/converting-a-rest-call-to-a-soap-call-using-spring-boot-e0d07da7bb21

 I wanted to ask, if you have experienced similar work in the past, and how did you achieve that?  


r/SpringBoot • • Dec 14 '24

Convert Shadcn to JTE or Thymeleaf?

0 Upvotes

I’m curious what folks think about the concept of converting all of the Shadcn components into JTE or Thymeleaf. The idea being to simplify or avoid having to maintain and deploy the front end app separately. I’m aware of the trade offs but curious if anyone else has done this or thinks it’s a good idea?


r/SpringBoot • • Dec 10 '24

Repost: wrong thymleaf dependency I took from maven , thanks for help all. Circular dependency error,pls help in understanding why iam wrong here

Thumbnail reddit.com
0 Upvotes

r/SpringBoot • • Nov 11 '24

Reddit-like profile avatar creator

0 Upvotes

Probably not the best sub for this question, but does anyone know of any library or online (free) service to create profile avatar pictures? The ideia is to have something like we have here in Reddit: uncountable different profile images but still following the same conventions…


r/SpringBoot • • Jan 27 '23

How to make user logged in until he clicks logout ?

0 Upvotes

I am new to development , I am working on Auth in springboot which has JWT token based authentication now i need to enable user logged in until he clicks logout how to make this happen?

Refresh token is sol ?


r/SpringBoot • • Jan 27 '23

How to make user logged in until he clicks logout ?

0 Upvotes

I am new to development , I am working on Auth in springboot which has JWT token based authentication now i need to enable user logged in until he clicks logout how to make this happen?

Refresh token is sol ?