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

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

Related

Autowire in spring understanding [duplicate]

This question already has answers here:
Understanding Spring #Autowired usage
(3 answers)
Closed 3 years ago.
When we use #Autowire annotation in spring to crete the object is it mandatory to specify the bean in configuration class ? And how does #Autowired work in springboot?
It's not mandatory in many cases, for instance when injecting objects annotated as #Entity, #Repository, #Controller, #Service or #Component (superclass of all the others) declared
within the main package where the #SpringBootApplication is placed.
You can always place components outside the main package if you declare a component scan in additional packages, using #ComponentScan({"package_1",..."package_n"}) in your #SpringBootApplication class. Remember to include the main package in the list.

Programmatic servlet registration in Spring Boot 2 [duplicate]

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/*");
}

Why does a Spring bean have to be Serializable? [duplicate]

This question already has answers here:
Why Java Beans have to be serializable?
(2 answers)
Difference between JavaBean and Spring bean
(4 answers)
Closed 3 years ago.
PMD spots many Spring components I have, with non-accessable members (no getters or setters), and says the following:
If a class is a bean, or is referenced by a bean directly or
indirectly it needs to be serializable. Member variables need to be
marked as transient, static, or have accessor methods in the class.
Marking variables as transient is the safest and easiest modification.
Accessor methods should follow the Java naming conventions, i.e. for a
variable named foo, getFoo() and setFoo() accessor methods should be
provided.
And I wonder, why does a Spring component/bean has to be Serializable??
Also, is it backed up by Spring documentation (I didn't find...)
I don't remeber having written "all" my Spring components as being Serializable, and I am not sure why they should be.
However, data components that can be stored in a database, and components that can be transported on a network must be. It's part of the trade-off for the Spring style Java Beans to be simple POJOs.
In the older days, JEE Java Beans (aka EJB) had to implement many features in order to be managed by the application container. Spring came along, as a light weight app container and changed all that. Spring manages simple POJOs, so I guess having it serializable is not too bad of a trade off.

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