Programmatic servlet registration in Spring Boot 2 [duplicate] - spring-boot

This question already has answers here:
How can I register a secondary servlet with Spring Boot?
(7 answers)
Closed 3 years ago.
I want to programmatically register servlet in Spring Boot 2 using embedded Tomcat.
I found here that this is possible using WebApplicationInitializer. Later I realized that this approach does not work with embedded Tomcat.

what about using ServletRegistrationBean?
#Bean
public ServletRegistrationBean servletRegistrationBean(){
return new ServletRegistrationBean(new FooServlet(),"/someOtherUrl/*");
}

Related

No qualifying bean of type 'com.spring.Dao.UserRepository' available [duplicate]

This question already has answers here:
Why is bean not found during Spring Boot?
(5 answers)
Why Spring Boot is not finding a #Service bean trying to perform autowiring? the bean exist but it can't find it
(3 answers)
Closed 3 months ago.
enter image description here
please help me solving this problem
i want to resolve this bug, how can i place or check my file in root package

Use Spring application properties without starting server [duplicate]

This question already has an answer here:
Spring-boot application-test.properties
(1 answer)
Closed 2 years ago.
We are using Spring Boot 2.3.4
We have some Unit tests where we would only need the application.properties to be loaded (with all it's profile management aso.).
Is it possible to do that without starting the complete Spring Boot server?
EDIT:
I tried the #SpringBootTest annotation, but it always started the whole server, because I referenced the #SpringBootApplication class (or it was referenced automatically).
Actually you don't need all the other annotation, like #ConfigurationProperties
All you need is #SpringBootApplication(classes = AClass.class), where AClass is any class that doesn't have a main method, like your test class for example.
Annotate your test class with #SpringBootTest to load the context.

How to disable the spring security login page though there is spring security dependency? [duplicate]

This question already has answers here:
Spring Boot 2.0.x disable security for certain profile
(7 answers)
Closed 4 years ago.
My spring boot version is 2.0.5.RELEASE.
I have been getting default login page when added the spring security dependency. I don't want to remove the spring security dependency but want to disable this login for certain time. I have tried to add them
security.ignored=/**
in application.properties file but it is not supporting it. It says that it is deprecated.
I want to add these disabling properties in the application.properties file but not getting the solution.
I usually add extra configuration, for allow access:
#Configuration
public class SecurityDisableConfiguration extends WebSecurityConfigurerAdapter {
#Override
protected void configure(final HttpSecurity http) throws Exception {
http.cors().disable()
.csrf().disable()
.httpBasic().disable()
.authorizeRequests().antMatchers("/**").permitAll();
}
}

AuthenticationManager returns NullPointerException [duplicate]

This question already has answers here:
Spring JSF integration: how to inject a Spring component/service in JSF managed bean?
(4 answers)
Closed 7 years ago.
I'd like to do a login page for my web application. On my example project that I found on internet for integrating Spring Security and LDAP, I got it working. When I tried to integrate working example to real app, I'm always gettin NullPointerException.
You have both spring annotation AND jsf annotations on the same class, so if you refer to them by different names (like you most likely did seeing your own 'answer'), you get different instances. That is not good and the cause of your original problem. Most likely (and you did not post your xhtml) you referred to the bean in your xhtml as loginViewBean. Now you removed that AND (I suspect) you started referring to it as loginView, you got the Spring managed instance back with the authenticationManager injected, instead of the JSF managed one without the authenticationManger injected. This resulted in the NPE. That you got the Spring one back then is most likely caused by the SpringEL resolver that you configured having precedence over the default JSF resolver. So removing the #ManagedBean and #RequestScoped AND refering to the bean by the spring name would have solved the problem to and in a better way.
See also
Spring JSF integration: how to inject a Spring component/service in JSF managed bean?
Solved my question.
I just need to edit this line
#ManagedBean(name = "loginViewBean")
to
#ManagedBean
And do the rest configuration on login.xhtml file. And it's done.

Difference between BeanFactory and ApplicationContext? [duplicate]

This question already has answers here:
BeanFactory vs ApplicationContext
(22 answers)
Closed 9 years ago.
Both are actually ioc containers. But what is the actual difference between them? Which one is better to use?
ApplicationContext is derived from BeanFactory to provide added functionality to work in web application.
You can instantiate your spring container by just writing
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
or
ApplicationContext context = new ClassPathXmlApplicationContext{"spring_dao.xml","spring_service.xml};
You can use one or more xml file depending on your project requirement. As I am here using two xml files i.e. one for configuration details for service classes other for dao classes. Here ClassPathXmlApplicationContext is child of ApplicationContext.
For better understanding the difference your can check the http://docs.spring.io/spring/docs/2.5.x/reference/beans.html#context-introduction-ctx-vs-beanfactory site.
Choosing between BeanFactory and ApplicationContext is also depends how you want load your beans.
ApplicationContext is preferred unless you need to save resources, like on a mobile application.
Both BeanFactory and Application are used to manage life cycle of beans, ApplicationContext can do all things that a BeanFactory does along with AOP,Event etc..
Unless until resources are crucial, go for ApplicationContext.

Resources