Fix LazyInitializationException: could not initialize proxy Error

While working with Hibernate you might have encountered the following error- org.hibernate.LazyInitializationException could not initialize proxy – no Session In this tutorial we’ll see why this error comes up and what is the best way to fix it. Why LazyInitializationException : could not initialize proxy You may encounter this error…

Continue reading

Spring @ComponentScan Annotation

Spring framework can automatically detect the classes annotated with @Component and other stereotype annotations like @Repository, @Service, @Controller. You need some way to tell Spring where to look for classes annotated with one of these annotations. For that you can use Spring @ComponentScan annotation, you can also specify the base…

Continue reading

Spring @Autowired Annotation

Spring @Autowired annotation is used to automatically inject dependencies. Where to apply @Autowired annotation You can apply the @Autowired annotation to setter methods. See example. You can apply the @Autowired annotation to constructors. See example. You can apply @Autowired to fields. See example. You can also apply the annotation to…

Continue reading

Spring @Resource Annotation

For autowiring in Spring apart from using @Autowired annotation there is also support for JSR 330’s @Inject annotation and JSR-250 @Resource annotation. In this post we’ll see how to use Spring @Resource annotation for autowiring. @Resource annotation in Spring @Resource annotation can be used on fields or bean property setter…

Continue reading

Spring @Configuration Annotation

Spring @Configuration annotation helps in creating Java based configuration in Spring rather than relying on XML based configuration. Any class annotated with @Configuration indicates that a class declares one or more @Bean methods that are processed by the Spring container to generate bean definitions and manage the overall bean lifecycle.…

Continue reading

Spring @Required Annotation

Spring @Required annotation is used with a method, typically a setter method thus making setter dependency injection for that property mandatory. RequiredAnnotationBeanPostProcessor class Registering RequiredAnnotationBeanPostProcessor class is required to use @Required annotation. A default RequiredAnnotationBeanPostProcessor will be registered by the “context:annotation-config” and “context:component-scan” XML tags. Spring @Required annotation examples In…

Continue reading