Posts

Exception handling in java

!! While adding data in database, types of exception can occurs !! @PostMapping ( "/add" ) public Employee addEmployee ( @RequestBody Employee employee) { return employeeService .saveEmployee(employee); } When adding data to a database in a Spring Boot application, several types of exceptions can be thrown. These exceptions may arise from various layers, including Spring Data , JPA , or the underlying JDBC driver . Below is a categorization of potential exceptions: 1. Data Access Exceptions (Spring Framework) Spring wraps exceptions from the persistence framework or database in subclasses of DataAccessException . Common exceptions include: DataIntegrityViolationException Occurs when constraints (e.g., unique, foreign key, not null) are violated. DuplicateKeyException Thrown for unique constraint violations or duplicate entries. EmptyResultDataAccessException Happens if a query expecting a result (e.g., findById) returns no data. IncorrectResultSizeDataAccessException...

Error : Project facet Java version 10 is not supported.

Image
 Solution ::  Go to Ecllipse , right click on your project folder select the properties now select Project Facets ,here you will see java, click on the version that you have jdk installed  then click on apply & close

Errors faced during building of java applications

Errors  : 1. String cannot be resolved to a type Why this error occurs   : when your required JRE is missing (for the current Java version)  How to add JRE in your projects  1. right click on projects ->properties->Libraries-> ClassPath->add external Jar ->path of your jre here(eg.  C:\Program Files\Java\jre1.8.0_281\lib ) link: https://stackoverflow.com/questions/7651768/string-cannot-be-resolved-to-a-type-java-rad

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource

  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver Solution:  add dependency for autoconfigure <dependency>   <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-autoconfigure</a...

IOC Container

 IOC Container(Spring) The IoC container is responsible to instantiate, configure and assemble the objects. The IoC container gets informations from the XML file and works accordingly. The main tasks performed by IoC container are: 1. Create the object  2. Hold them in a memory 3. Inject them in another object as required 4. Maintain the whole lifecycle of objects There are two type of  IOC container 1. BeanFactory 2.  ApplicationContext

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver

Image
 this error occurs in springboot application solution goto application.properties file and enable spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. [2m2021-04-04 21:55:17.475 [0;39m [31mERROR [0;39m [35m18524 [0;39m [2m--- [0;39m [2m[ main] [0;39m [36mo.s.boot.SpringApplication [0;39m [2m: [0;39m Application run failed

Image
This error arise while run springboot application Solution step1    open application.properties file then enable         debug=true          server.port=8014