ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@769f71a9: startup date [Tue Nov 21 15:46:02 IST 2017]; root of context hierarchy 2017-11-21 15:46:24.774 INFO 6272 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2017-11-21 15:46:24.922 INFO 6272 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2017-11-21 15:46:24.924 INFO 6272 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.23 2017-11-21 15:46:25.250 INFO 6272 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_141\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Windows\system32\config\systemprofile.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies\;C:\Program Files\nodejs\;C:\Program Files\Java\jdk1.8.0_141\bin;C:\Users\kaleti\AppData\Local\Microsoft\WindowsApps;C:\Users\kaleti\AppData\Roaming\npm;C:\Users\kaleti\AppData\Local\GitHubDesktop\bin;.] 2017-11-21 15:46:25.628 INFO 6272 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2017-11-21 15:46:25.629 INFO 6272 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 23087 ms 2017-11-21 15:46:25.986 INFO 6272 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2017-11-21 15:46:25.986 INFO 6272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/] 2017-11-21 15:46:25.986 INFO 6272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/] 2017-11-21 15:46:25.986 INFO 6272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/] 2017-11-21 15:46:25.986 INFO 6272 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/] 2017-11-21 15:46:26.625 WARN 6272 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'statusController': Unsatisfied dependency expressed through field 'statusService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'statusService': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repositoryImpl': Cannot create inner bean '(inner bean)#340b7ef6' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#340b7ef6': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available 2017-11-21 15:46:26.656 INFO 6272 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2017-11-21 15:46:26.788 INFO 6272 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2017-11-21 15:46:26.983 ERROR 6272 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter
APPLICATION FAILED TO START***************************
Description: Field repository in com.learing.demo.StatusService required a bean named 'entityManagerFactory' that could not be found. Action:
Consider defining a bean named 'entityManagerFactory' in your configuration.
Process finished with exit code 1
My Code as Below
package com.learing.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
StatusController class
package com.learing.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class StatusController {
@Autowired
private StatusService statusService;
@RequestMapping("/getEmpStatus")
public List<Employee> GetAllEmployeeStatus(){
return statusService.GetAllEmpStatus();
}
@RequestMapping("/getEmpStatus/{id}")
public Employee GetAllEmployeeStatus(@PathVariable int id){
return statusService.GetEmpStatus(id);
}
@RequestMapping(method= RequestMethod.POST, value="/getEmpStatus")
public void AddEmployeeStatus(@RequestBody Employee employee){
statusService.AddEmployeeStatus(employee);
}
@RequestMapping(method = RequestMethod.PUT, value="/getEmpStatus/{id}")
public void UpdateStatus(@RequestBody Employee employee, @PathVariable int id){
statusService.UpdateStatus(employee,id);
}
@RequestMapping(method= RequestMethod.DELETE, value="/getEmpStatus/{id}")
public void UpdateStatus(@PathVariable int id){
statusService.DeleteStatus(id);
}
}
StatusService class
package com.learing.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class StatusService {
@Autowired
public RepositoryImpl repository;
private List<Employee> employees = new ArrayList<>(Arrays.asList(new Employee(1, "NSIN253", "Kalpa", "BHS-Mapping", "Mapping doc Completed"), new Employee(2, "NSIN254", "Fareeda", "BHS-Mapping", "Mapping doc Completed"), new Employee(3, "NSIN252", "KrishnaVeni", "BHS-Mapping", "Mapping doc Completed")));
public List<Employee> GetAllEmpStatus() {
return employees;
}
public Employee GetEmpStatus(int id) {
return employees.stream().filter(employee -> employee.getiD() == id).findFirst().get();
}
public void AddEmployeeStatus(Employee employee) {
repository.save(employee);
}
public void UpdateStatus(Employee employee, int id) {
for (int i = 0; i < employees.size(); i++) {
Employee emp = employees.get(i);
if (emp.getiD() == id) {
employees.set(i, employee);
}
}
}
public void DeleteStatus(int id) {
employees.removeIf(emp -> emp.getiD() == id);
}
}
RepositoryImpl class
package com.learing.demo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface RepositoryImpl extends CrudRepository<Employee,Integer> {
}
application props:
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=EmployeeDb
spring.datasource.username=xxxx
spring.datasource.password=xxxxx
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto =update
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>com.learing</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>