Spring boot ManagedExecutorService instance - java

We are creating a new Spring Boot project and a part of it needs multi-threading operation. We are trying to use the ManagedExecutorService, so we declared it as follows:
#Resource(name="java:comp/DefaultManagedExecutorService")
private ManagedExecutorService mes;
And during execution returned the error:
Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name 'java:comp/DefaultManagedExecutorService' defined in JNDI environment: JNDI lookup failed; nested exception is
javax.naming.NoInitialContextException: Need to specify class name in
environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
Does this means that Spring Boot does not support/allow us to use the ManagedExecutorService in tomcat?

Related

Integrating rqueue with spring boot application

Error creating bean with name 'rqueueConfig' defined in class path resource [com/github/sonus21/rqueue/spring/boot/RqueueListenerAutoConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.sonus21.rqueue.config.RqueueConfig]: Factory method 'rqueueConfig' threw exception; nested exception is java.lang.UnsupportedOperationException: Scripting commands not supported in pipelining/transaction mode
Followed steps mentioned on the website, https://github.com/sonus21/rqueue
There, it was mnentioned #EnableRqueue annotation, but it gave me a error, that it cannot find the annotation.
I am using JAVA 11 and spring boot framework.

Restart spring boot application using actuator in wildfly

I am trying to use Spring Boot Actuator to restart the spring to update its newest properties.
I followed this tutorial:
https://javapointers.com/spring/spring-boot/how-to-restart-spring-boot-automatically-using-actuator/
So what I did is just to add the properties
management.endpoint.restart.enabled=true
management.endpoints.web.exposure.include=restart,health
and call the endpoint
{host}/actuator/restart
I tested it on my local using the embedded tomcat server, and it works.
But when I tried it in jboss/wildfly, because my client are using it for their production server, it doesn't work.
This is the error that I got:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'server-org.springframework.boot.autoconfigure.web.ServerProperties': Could not bind properties to 'ServerProperties' : prefix=server, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.IllegalStateException: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#3aa3a991 has been closed already
Please let me know if there is something else that I need to provide.
Maybe You could take a look at Spring Cloud Config to solve properly your problem : Spring Cloud Config
It allow you to externalize properties, manage them and expose them to clients (like your application).
And it has some benefits like 'No restart needed'

Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource

I am getting below error after updating spring-boot starter parent to 2.4.3. But after setting up server.servlet.register-default-servlet=true application is working as expected. But one i would like to know is, in the reference spring documentation >Spring Boot 2.4 will no longer register the DefaultServlet provided by your servlet container. In most applications, it isn’t used since the Spring MVC’s DispatcherServlet is the only servlet that’s required.
So do i missing anything as my application is not considering DispatcherServlet as default one
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultServletHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'defaultServletHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException: Unable to locate the default servlet for serving static content. Please set the 'defaultServletName' property explicitly.
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)

Spring boot is picking wrong CorsFilter

I am working on a spring boot web application with security features. I am relying on a library with a custom Cors Filter that I need to use but my application keeps picking the Spring Web Framework Cors Filter instead and renders the following error:
[ERROR] Failed to execute goal
org.springframework.boot:spring-boot-maven-plugin:2.0.5.RELEASE:run
(default-cli) on project tools-services: An exception occurred while
running. null: InvocationTargetException: Error creating bean with
name 'springSecurityFilterChain' defined in class path resource
[org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [javax.servlet.Filter]: Factory method
'springSecurityFilterChain' threw exception; nested exception is
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean
named 'corsFilter' is expected to be of type
'org.springframework.web.filter.CorsFilter' but was actually of type
'com.myproj.sample.inf.sec.filter.CorsFilter' -> [Help 1]
I am trying to create a CorsFilter bean in my Application.java class as such:
#Bean
public CorsFilter corsFilter() {
return new CorsFilter();
}
However, this gives me the same error. Is there a way to make Spring Boot point to the custom cors filter or disable the spring cors filter?
Probably is because of the same name. Can you try to change bean name used in your Application.java?

How do I properly configure Spring OAuth 2 for Web UI log in?

I have the OAuth 2 configuration working properly, and I'm currently in the process of enabling Web UI as well. Since the configuration involves Web security, I already have part of it set up. Actually, my understanding is that I don't really have much more to add anymore, other than the MVC components (like the login page, URL mappings, etc.) However, I'm having trouble logging into the Web app since the user is being tagged as anonymousUser.
Both WebSecurityConfigurerAdapter and ResourceServerConfigurerAdapter define method configure(HttpSecurity). Currently, I'm using the one defined in ResourceServerConfigurerAdapter but that's where I'm experiencing the User being tagged as anonymous. If I try using the one in WebSecurityConfigurerAdapter (with OAuth 2 currently configured), I get the following error message:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer#546ed2a0 to already built object
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
...
Caused by:
Caused by: java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer#546ed2a0 to already built object
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.add(AbstractConfiguredSecurityBuilder.java:196) ~[spring-security-config-4.1.3.RELEASE.jar:4.1.3.RELEASE]
...
However, when I disable everything related to the OAuth 2, and only use WebSecurityConfigurerAdapter (with HttpSecurity set up), login via the Web UI works as expected (i.e. user is not tagged as anonymous). I'm not sure what key area I got wrong on this.

Categories

Resources