These are chat archives for spring-cloud/spring-cloud

26th
Jul 2018
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 05:59
hello everyone
i have a problem
when i upgrate to spring cloud finchley it comes
XSS protect works well on low version about spring cloud
but now it's not work
and throws exception and i cannot find why that
follow error info:
"status": 500,
"error": "Internal Server Error",
"message": "Request processing failed; nested exception is java.lang.IllegalArgumentException: Input is required"
anyone else can help me ?
11ssss
@poppycokey
Jul 26 2018 06:01
Can you take a screenshot?
from console
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 06:02
ok , wait a moment
11ssss
@poppycokey
Jul 26 2018 06:03
Do you use WeChat?
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 06:03
yeah
11ssss
@poppycokey
Jul 26 2018 06:05
so good ,you wechar num is?
wechat
dharezlak
@dharezlak
Jul 26 2018 07:16
@tkvangorder Thanks for the link, however, I can't find any info on why there are two environment initialization calls and how to distinguish them. Do you have any insight on that?
dharezlak
@dharezlak
Jul 26 2018 08:39
I have created a small project reproducing the environment initialization issue here: https://github.com/dharezlak/envboot
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 08:41
@dharezlak ok, l am facing this demo
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 09:12
@dharezlak hi
in you project pom file
spring-cloud-starter-gateway
this dependency has redependency webflux etc...
remove this redependency , and then it 's work well
autoconfigration is spring boot important initial rule
in finchley version change is too big
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 09:19
please let me know if you have any concerns @dharezlak
dharezlak
@dharezlak
Jul 26 2018 09:28
@ggpopovich_twitter I don't understand why maven's transitive dependencies would impact Boot's autoconfiguration. Anyway, after removing the spring-boot-starter-webflux dependency the problem persists. The Running environment post processor... log shows twice in the app's output.
Gregg Popovich
@ggpopovich_twitter
Jul 26 2018 09:29
ok ok, and i know that webflux is new feature
and it comes just one selector
and i think between those dependencies will be enhance in the next version
dharezlak
@dharezlak
Jul 26 2018 09:51
@ggpopovich_twitter Would you consider this a bug worth reporting?
dharezlak
@dharezlak
Jul 26 2018 14:12

Hi, after some reading I can only assume that an EnvironmentPostProcessor is run for each of the application contexts being initialized and for a Spring Cloud project the additional run comes from running the bootstrap context. In the Spring Cloud documentation there is a following statement:

... Note that the SpringApplicationBuilder allows you to share an Environment amongst the whole hierarchy, but that is not the default...

How can I make the environment be shared among different context hierarchy? I tried invoking the .environment method like this:

new SpringApplicationBuilder(MyApplication.class)
                .environment(new StandardEnvironment())
                .build()
                .run(args);

It did not help. My post processor still runs twice with separate property sources.

dharezlak
@dharezlak
Jul 26 2018 14:36

I finally ended up with the following:

System.setProperty("spring.cloud.bootstrap.enabled", "false");
SpringApplication.run(MyApplication.class, args);

Now, my environment post processor is run once with all the property sources merged. Ufff ;)

dharezlak
@dharezlak
Jul 26 2018 15:09
I also had to set @SpringBootTest(webEnvironment = RANDOM_PORT, properties = "spring.cloud.bootstrap.enabled = false") for each of my tests :/
Tyler Van Gorder
@tkvangorder
Jul 26 2018 15:27
@dharezlak I am not sure its a good idea to disable the bootstrap context. The first context is used to initialize the application context and provides the ability to use the config server to pull in externalized configuration. (I highly recommend taking a look at Spring Cloud Config for details). Your post processor is getting called for each context and it sounds like you really only want the logic in your processor to fire in the application context. If you must only fire this logic once, why not just write some code to detect which context is being initialized and then short circuit if its the bootstrap context?
Joshua Street
@jjstreet
Jul 26 2018 16:53
hey all, question that is hopefully answerable
im looking at spring-cloud-gateway
i want to create a filter factory that uses a component or two
can i annotate my filter factory with @Component and autowire through the constructor?
my gut tells me this is ok
or i could create it through config class and inject manually
KaijuDeluxe
@KaijuDeluxe
Jul 26 2018 19:48

hi i am getting
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

but i dont use Database in the service, whats that?

dharezlak
@dharezlak
Jul 26 2018 20:08
@tkvangorder Hi, thanks for the comment. I did not find any way to check from within the processor which context is being initialized. So far my idea is to look at property sources and check if a bootstrap property source is present. That is when I do not want my logic to kick in. Any other ideas on this?