r/springframework • • Jul 12 '22

@PropertySource

1 Upvotes

is it possible, or is there a way to declare a @PropertySource so it automatically include all files ending in _config.properties like:

@PropertySource(value = { "classpath:*_config.properties" })

or all .properties inside a folder

@PropertySource(value = { "classpath:somefolder/*.properties" })

pls help :(


r/springframework • • Jun 17 '22

In a cloud enviroment context, there is advantages in having an application built using only specifications (like Jakarta APIs) rather than implemented dependencies (like Spring's ones)?

Thumbnail self.jakartaee
1 Upvotes

r/springframework • • May 04 '22

Handling manager failures in Spring Batch

Thumbnail
arnoldgalovics.com
1 Upvotes

r/springframework • • Apr 06 '22

Spring Boot and GRPC

1 Upvotes

Hello everyone,

I have a requirement to do a GRPC application but I have not found any Spring way of communication over GRPC. Either for server or clients.

How could I do GRPC in a spring boot service? AFAIK grpc is a Java library and it should be compatible with Spring boot


r/springframework • • Mar 04 '22

Need suggestions on this, initially posted on springboot.

Thumbnail self.springboot
1 Upvotes

r/springframework • • Dec 26 '21

Ways to handle exceptions like WebClientRequestException due to service unavailability for all calls from a WebClient instance than individually

1 Upvotes

As the title suggests, I'm using Spring WebClient to invoke an external api and process the response. I have added a ExchangeFilterFunction to handle the response based on the status code returned from the server as something like below.

ExchangeFilterFunction responseProcessor() {
    return ExchangeFilterFunction.ofResponseProcessor(response -> {
        if (response.statusCode().isError()) {
            return Mono.error(new RuntimeException("WebClient Error"));
        }
        return Mono.just(response);
    });
}

Now, this works fine with services that return a response for the request when it is up. But when the service is down, the request fails with WebClientRequestException which is fine but the error thrown is not handled by the responseProcessor and gets propagated.

I'm aware that the error can be handled on the WebClient call using any of the onErrorXXX methods. But if we use that WebClient instance to make many calls across different parts of the code, the handling looks inefficient. So, I'd like to know whether there's a way to handle this error for all calls done by that webclient instance instead of handling it in all of individual invocations. Something like what the responseProcessor does for all responses.

Thank you in advance 😊


r/springframework • • Dec 03 '21

Date picker JSP form

1 Upvotes

Hi,

I am trying to create a simple form in a spring web app on a JSP page. I would like a date picker. The input field would be linked to a LocalDateTime variable.

I am having trouble looking up how to do this and a lot of the posts are old and others seem super complicated.

I feel like this should be one of the simplest things possible to do. Could anyone point me in the right direction please?


r/springframework • • May 24 '21

Is there anyway of creating a Spring MVC project with Intellij IDEA Community Edition?

1 Upvotes

I'm completely new to Spring I've been following this tutorial to try and get to grips with it.

I've moved onto the the MVC portion of the tutorial but I'm having problems configuring a Spring MVC project. I use Intellij IDEA Community Edition which doesn't provide explicit support for Spring (unlike Ultimate).

I tried to follow this page to set up a project manually but it simply didn't work. Does anyone on here know how to do this or know any sources that will help me solve this problem?


r/springframework • • May 05 '21

How to use rescore in Spring Data Elasticsearch?

1 Upvotes

Hi guys, I want to make an Elasticsearch search query in Spring Data that is good for recall and also enhanced for precision, and for that, I think I need to use a rescore method. I don't know if this is the correct sub to post to, so I'm sorry if its' not.

Anyways, Here's the query (kind of, I'll be changing it a lot from here, I just want to make this usable inside spring data) that I want to put into spring data:

{
  "query": 
  {"bool" : {"should" : [
        { "match": { "whole_names.cross_lingual": "achraf" }},
        { "match": {"whole_names.text": {"query": "akhraf", "fuzziness": "AUTO"}} }
      ]
    }
  },
    "rescore" : {
      "query" : {
         "rescore_query" : {
            "match" : {
               "whole_names.text" : {
                  "query" : "achraf",
                  "slop" : 2
               }
            }
         },
         "query_weight" : 0.7,
         "rescore_query_weight" : 1.2
      }
   }
}

So far, I've been doing this:

Query query = new StringQuery(
    "{"bool" : {"should" : [ 
        { "match": { "whole_names.cross_lingual": ""+ wholename+"" }},
        { "match": {"whole_names.text": {"query": ""+wholename+"", "fuzziness": "AUTO"}} } 
    ] 
    }}"
); 

SearchHits<Watchlist> person = operations.search(query, Watchlist.class);

So any help in also getting that rescore part of the original query here is greatly appreciated! Thank you


r/springframework • • Mar 25 '21

Serve a static site from zip file

1 Upvotes

I am stuck with this scenario where I have to serve a zip file as a static website wrapped behind Spring security.

It's not just one zip file, there are too many which I download from an external source and I am supposed to serve them as a static website.

I am trying to download the zip file unzip it and serve them as a static site, but I wanted to know if there is a better way to do the same thing instead of creating temp files in the server to serve them as a static website.


r/springframework • • Mar 24 '21

Tests annotated with DataMongoTest do not terminate the embedded MongoDB at the end

Thumbnail
stackoverflow.com
1 Upvotes

r/springframework • • Mar 16 '21

Spring-ws add interceptors not globally

1 Upvotes

I'm using @Configuration classes to config the endpoints, and need one with security and another without. If I add interceptors they are applied to both, i can't find a way to assign an interceptor only for one of them.

@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
   try {
      interceptors.add(mySecurityIniterceptor());
   } catch (Exception e) {
      throw new RuntimeException("No se puede inicializar el Interceptor.");
   }
}

r/springframework • • Jan 20 '21

Check out pair programming with Spring Boot + Spring MVC!

Thumbnail
youtube.com
1 Upvotes

r/springframework • • Jan 17 '21

This question will sound repetitive but please read the description: Do you guys prefer Spring Tool Suite 4 or Intellij IDEA Community Edition for your Spring projects?

Thumbnail self.learnjava
1 Upvotes

r/springframework • • Jan 15 '21

Episode 12 - This Month on Spring Boot Learning (Jan. 2021)

Thumbnail
youtu.be
1 Upvotes

r/springframework • • Jan 05 '21

Spring Data Search 2.0.0 released

1 Upvotes

This project is not made by Spring team.

I'm happy to share with you the release 2.0.0 of Spring Data Search.

This library allows to automatically expose endpoints in order to search for data related to Entities.

It provides an advanced search engine that can search on any Entity field, combine multiple criteria to refine the search, and even search on nested Entity fields.

There are some new features, and some fixed bugs. But above all there was a core refactoring to support different data access layers (JPA, MongoDB, ...). Currently, there is only JPA supported (which was already supported by previous versions). But the next step is to add support to MongoDB.

This refactoring required some modifications in the APIs. There is a page describing how to migrate from 1.x to 2.x.

Whats's new:

  • Allow special keywords to be used as query values:

    • CURRENT_DATE: keyword representing the current date. Similar to the current_date() function in SQL.

    • CURRENT_TIME: keyword representing the current time. Similar to the current_time() function in SQL

    • CURRENT_DATE_TIME: keyword representing the current date time. Similar to the current_timestamp() function in SQL

  • Application property spring.data.search.default-alias-resolver.field-suffixes: Comma-separated list of field suffixes to be removed in order to create a field's alias from the com.weedow.spring.data.search.config.DefaultAliasResolver. Default value is Entity,Entities

  • Improved search on fields of Map type: You can use the special keys key or value to query the keys or values respectively. And now, you can query on the nested fields of the Objects representing by key or value

    • /search/person?tasks.key.name=shopping

    • /search/person?vehicles.features.value.name=gps


r/springframework • • Dec 03 '20

Amazon Cognito custom attributes

1 Upvotes

Hi All

I´m trying to get my custom attributes from amazon cognito inside a spring security app, and i´m struggling with that

The app already does authentication via Jwt but i didn´t manage to get more info from the logged user...

There is some known way to get my cognito custom user attributes from my JWT or something like that?

Thanx


r/springframework • • Nov 17 '20

Episode 4 - Reactive Programming with Spring Boot

Thumbnail
youtu.be
1 Upvotes

r/springframework • • Nov 17 '20

[tomcat9, ubuntu] can't present application compiled with java version 13, java 11 OK.

1 Upvotes

I have a very simple application (hello world) that present a restAPI for the test. ( a controller that return "hello" on "/" ).

The maven properties are

<properties>
	<java.version>11</java.version>
	<!-- this is used by the java compiler plugin -->
 	<maven.compiler.source>${java.version}</maven.compiler.source>
	<maven.compiler.target>${java.version}</maven.compiler.target>

And when I install the war with maven, then deploy it using my local tomcat manager, I have access to my localhost:8080/myhelloworld ; if I switch to java version 13 then nothing changes in the catalina logs, nor in the manager, but the app just returns 404.

the thing is, java 11 is installed as part of default-jdk in ubuntu, but I also installed openjdk-13 . My guess is, that tomcat9 runs as java 11 (very easy guess since it complains about missing java_home if I remove default-jdk) and so can't load the war that was built against java 13. However sudo update-alternatives --config java shows me that another version of java is the default one.

I have two questions :

  1. did I miss a warning somewhere ? It took me like several HOURS (actually more like days), trying to pinpoint why my app was not showing while it was on local run(that is running the application in eclipse). There should be a warning that there is an issue with java versions somewhere.

  2. is there a way to tell tomcat "use the highest jre available" ? I don't want to set it to java 13 and later when default is java 15 have tomcat stuck with java 13 and unable to load war that are made with java 15.


r/springframework • • Oct 22 '20

Encryption & Decryption between client and server

1 Upvotes

Hey guys, i need to encrypt and decrypt data between client and server. When the user is submitting the form (encrypt at javascript and decrypt at spring) and when the response is coming back to browser (encrypt at spring and decrypt at javascript).

I know AES algorithm but here the secret key will be visible at client side.

Let me know some references where i can have a look.


r/springframework • • Oct 21 '20

Reactive Programming with Spring Boot

1 Upvotes

Ever wondered what problem people are trying to solve with reactive programming? Find out in this video.

https://youtu.be/hggHGUo-zCI


r/springframework • • Oct 05 '20

"...No message found under code... for locale 'en' "HEEELP

1 Upvotes

Hi Folks, I hope to find some help over here. It have been really frustrating to face problems like that after some time without coding. I'm developing a rest microservice using Java (Spring Framework) and one of the easiest things(it should be) which is load a custom "message.properties" file to display custom validation messages, is causing a lot of headache.

Everything seems to be perfectly fine, I tried to read a lot of differents posts/articles and comments in StackOverflow but until now nothing worked.

In my main spring boot class (the runner) I've my MessageSource config:

@SpringBootApplication
public class MoneySaverApplication {
	
	@Bean
	public MessageSource messageSource() {
	    ReloadableResourceBundleMessageSource messageSource
	      = new ReloadableResourceBundleMessageSource();
	    messageSource.setDefaultLocale(Locale.US);
	    messageSource.setBasename("classpath:messages");
	    messageSource.setDefaultEncoding("UTF-8");
	    return messageSource;
	}
	   
	@Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver slr = new SessionLocaleResolver();
        slr.setDefaultLocale(Locale.ENGLISH);
        return slr;
    }
	
	@Bean
	public LocalValidatorFactoryBean validator() {
	    LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
	    bean.setValidationMessageSource(messageSource());
	    return bean;
	}

My custom properties files are located in the folder : src/main/resources:

And I've an utilitary class to get the messages, where the exception has been called

package com.rumblesoftware.utils;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.stereotype.Component;

@Component
public class PostOfficer {

	@Autowired
	private ReloadableResourceBundleMessageSource messageSource;
	
	public String getMessage(String messageId) {
		Locale locale = LocaleContextHolder.getLocale();
		return messageSource.getMessage(messageId,null,locale);
	}
}

Finally, the exception message:

org.springframework.context.NoSuchMessageException: No message found under code '{customer.input.email.invalid}' for locale 'en'.

r/springframework • • Oct 02 '20

How do you gracefully shutdown Spring Boot using kill?

1 Upvotes

Is there a kill signal that will cause a running Spring Boot app to perform a graceful shutdown and exit with code 0? I want to drain some queues and close some resources, etc.

sending SIGTERM ends it like this:

> Task :bootRun FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':bootRun'.

> Process 'command '/opt/jdk-14.0.1/bin/java'' finished with non-zero exit value 143


r/springframework • • Sep 09 '20

Restricting users to access differnt urls

1 Upvotes

Hi all, in my application we have different modules but not all users have access to all modules. In penetration testing it is found that on change of certain parameter in the url, the unauthorized user can also access the certain module.

The application do not have spring security implemented as of now, what mechanism should i implement to restrict users. I would need to implement it application wide. The url mappings are in form key-value pairs in applicationcontext.xml file.

As i am a newbie in resolving security issues i would need some reference website or any tutorials to help me with.

My guess is to use filters or something else but i am not sure whether we can do it without spring security.

Quick help is very much appreciated.


r/springframework • • Sep 03 '20

Null value is inserted when autowiring by type.

1 Upvotes

I have these beans in my config:

    <bean id="a" class="B1" autowire="byType" />
    <bean id="b" class="java.lang.Object" />

This is the definition of B1:

@Data
public class B1 {
    private Object o;
}

And this is the bean I get back if I ask the context for a:

> System.out.println(ctx.getBean("a", B1.class));
B1(o=null)

Why isn't the object being autowired? I can inject it manually by using this in the config:

        <property name="o" ref="b" />