Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.73 KB | None | 0 0
  1. [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.3.RELEASE:run (default-cli) on project demo: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active). -> [Help 1]
  2. [ERROR]
  3. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  4. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  5. [ERROR]
  6. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  7. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
  8.  
  9. package com.config;
  10.  
  11. import org.springframework.context.annotation.Bean;
  12. import org.springframework.context.annotation.Configuration;
  13. import com.dao.DepartmentDAO;
  14. import com.daoimpl.DepartmentDAOImpl;
  15.  
  16.  
  17. @Configuration
  18. public class Config {
  19.  
  20. @Bean
  21. public DepartmentDAO departmentDAO(){
  22. // DepartmentDAOImpl departmentDaoImpl = new DepartmentDAOImpl();
  23. return new DepartmentDAOImpl();
  24. }
  25. }
  26.  
  27. <?xml version="1.0" encoding="UTF-8"?>
  28.  
  29. <groupId>test.component</groupId>
  30. <artifactId>demo</artifactId>
  31. <version>0.0.1-SNAPSHOT</version>
  32. <packaging>jar</packaging>
  33.  
  34. <name>DemoHibernate</name>
  35. <description>Demo project for Spring Boot</description>
  36. <parent>
  37. <groupId>org.springframework.boot</groupId>
  38. <artifactId>spring-boot-starter-parent</artifactId>
  39. <version>1.3.3.RELEASE</version>
  40. <relativePath/> <!-- lookup parent from repository -->
  41. </parent>
  42.  
  43. <properties>
  44. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  45. <java.version>1.8</java.version>
  46. </properties>
  47.  
  48. <dependencies>
  49. <dependency>
  50. <groupId>org.springframework.boot</groupId>
  51. <artifactId>spring-boot-starter</artifactId>
  52. </dependency>
  53.  
  54. <dependency>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-starter-test</artifactId>
  57. <scope>test</scope>
  58. </dependency>
  59. <dependency>
  60. <groupId>org.springframework.boot</groupId>
  61. <artifactId>spring-boot-starter-data-jpa</artifactId>
  62. </dependency>
  63. <dependency>
  64. <groupId>org.springframework.boot</groupId>
  65. <artifactId>spring-boot-starter-web</artifactId>
  66. </dependency>
  67. <dependency>
  68. <groupId>org.hibernate</groupId>
  69. <artifactId>hibernate-core</artifactId>
  70. <version>3.6.3.Final</version>
  71. </dependency>
  72. <dependency>
  73. <groupId>javax.transaction</groupId>
  74. <artifactId>jta</artifactId>
  75. <version>1.1</version>
  76. </dependency>
  77. <dependency>
  78. <groupId>org.eclipse.persistence</groupId>
  79. <artifactId>eclipselink</artifactId>
  80. <version>2.5.1</version>
  81. </dependency>
  82. <dependency>
  83. <groupId>org.eclipse.persistence</groupId>
  84. <artifactId>javax.persistence</artifactId>
  85. <version>2.0.0</version>
  86. <scope>compile</scope>
  87. </dependency>
  88. <dependency>
  89. <groupId>mysql</groupId>
  90. <artifactId>mysql-connector-java</artifactId>
  91. <version>5.1.36</version>
  92. </dependency>
  93. <dependency>
  94. <groupId>org.springframework.boot</groupId>
  95. <artifactId>spring-boot-starter-web</artifactId>
  96. </dependency>
  97. <dependency>
  98. <groupId>org.springframework.boot</groupId>
  99. <artifactId>spring-boot-starter-tomcat</artifactId>
  100. </dependency>
  101. <dependency>
  102. <groupId>org.springframework.boot</groupId>
  103. <artifactId>spring-boot-starter-web</artifactId>
  104. </dependency>
  105. <dependency>
  106. <groupId>com.h2database</groupId>
  107. <artifactId>h2</artifactId>
  108. <version>1.3.156</version>
  109. </dependency>
  110.  
  111. <dependency>
  112. <groupId>org.springframework.boot</groupId>
  113. <artifactId>spring-boot-starter-data-jpa</artifactId>
  114. </dependency>
  115. <dependency>
  116. <groupId>org.hsqldb</groupId>
  117. <artifactId>hsqldb</artifactId>
  118. <scope>runtime</scope>
  119. </dependency>
  120. </dependencies>
  121.  
  122. <build>
  123. <plugins>
  124. <plugin>
  125. <groupId>org.springframework.boot</groupId>
  126. <artifactId>spring-boot-maven-plugin</artifactId>
  127. </plugin>
  128. </plugins>
  129. </build>
  130.  
  131. package com.controller;
  132.  
  133. import java.util.List;
  134.  
  135. import org.springframework.beans.factory.annotation.Autowired;
  136. //import org.springframework.stereotype.Controller;
  137. import org.springframework.web.bind.annotation.RequestMapping;
  138. import org.springframework.web.bind.annotation.RestController;
  139.  
  140. import com.dao.DepartmentDAO;
  141. import com.entities.Department;
  142.  
  143. //@Controller
  144. @RestController
  145. public class MainController {
  146. @Autowired
  147. private DepartmentDAO departmentDAO;
  148.  
  149. @RequestMapping({"/","/home","/index"})
  150. public String home(){
  151. return "index";
  152. }
  153.  
  154. @RequestMapping({"/deptList"})
  155. public String deptList() {
  156. departmentDAO.createDepartment("Dept Name", "Dept Location");
  157.  
  158. List<Department> list = departmentDAO.listDepartment();
  159. for (Department dept : list) {
  160. System.out.println("Dept No " + dept.getDeptNo());
  161. }
  162. // model.addAttribute("departments", list);
  163. return "deptList";
  164. }
  165. }
  166.  
  167. package com.dao;
  168.  
  169. import java.util.List;
  170. //import org.springframework.stereotype.Component;
  171. //import org.springframework.stereotype.Repository;
  172.  
  173. import com.entities.*;
  174.  
  175. //@Repository
  176. //@Component
  177. public interface DepartmentDAO {
  178. public List<Department> listDepartment() ;
  179. public Integer getMaxDeptId();
  180. public void createDepartment(String name,String location);
  181. }
  182.  
  183. package com.daoimpl;
  184.  
  185. import java.util.List;
  186.  
  187. import org.hibernate.Query;
  188. import org.hibernate.Session;
  189. import org.hibernate.SessionFactory;
  190. import org.springframework.transaction.annotation.Transactional;
  191.  
  192. import com.dao.DepartmentDAO;
  193. import com.entities.Department;
  194.  
  195.  
  196. @Transactional
  197. public class DepartmentDAOImpl implements DepartmentDAO{
  198.  
  199. private SessionFactory sessionFactory;
  200.  
  201. public void setSessionFactory(SessionFactory sessionFactory) {
  202. this.sessionFactory = sessionFactory;
  203. }
  204.  
  205. @SuppressWarnings("unchecked")
  206. @Override
  207. public List<Department> listDepartment() {
  208. Session session = this.sessionFactory.getCurrentSession();
  209. List<Department> list = session.createQuery("from Department").list();
  210. return list;
  211. }
  212.  
  213. @Override
  214. public Integer getMaxDeptId() {
  215. Session session = this.sessionFactory.getCurrentSession();
  216. String sql = "Select max(d.deptId) from Department d";
  217. Query query = session.createQuery(sql);
  218. Integer maxDeptId = (Integer)query.uniqueResult();
  219. if (maxDeptId == null){
  220. return 0;
  221. }
  222. return maxDeptId;
  223. }
  224.  
  225. @Override
  226. public void createDepartment(String name, String location) {
  227. Integer deptId = getMaxDeptId() + 1;
  228. Department dept = new Department();
  229. dept.setDeptId(deptId);
  230. dept.setDeptNo("D" + deptId);
  231. dept.setDeptName(name);
  232. dept.setLocation(location);
  233. Session session = this.sessionFactory.getCurrentSession();
  234. session.persist(dept);
  235. }
  236.  
  237. }
  238.  
  239. package com.entities;
  240.  
  241. import javax.persistence.Column;
  242. import javax.persistence.Entity;
  243. import javax.persistence.Id;
  244. import javax.persistence.Table;
  245. import javax.persistence.UniqueConstraint;
  246.  
  247.  
  248. @Entity
  249. @Table(name = "DEPARTMENT", uniqueConstraints = {
  250. @UniqueConstraint(columnNames = { "DEPT_NO" }) })
  251. public class Department {
  252. private int deptId;
  253. private String deptNo;
  254. private String deptName;
  255. private String location;
  256.  
  257. public Department(){
  258.  
  259. }
  260.  
  261. public Department(Integer deptId, String deptName, String location){
  262. this.deptId = deptId;
  263. this.deptNo = "D" + this.deptId;
  264. this.deptName = deptName;
  265. this.location = location;
  266. }
  267.  
  268. @Id
  269. @Column(name = "DEPT_ID")
  270. public int getDeptId() {
  271. return deptId;
  272. }
  273.  
  274. public void setDeptId(int deptId) {
  275. this.deptId = deptId;
  276. }
  277.  
  278. @Column(name = "DEPT_NO", length = 20, nullable = false)
  279. public String getDeptNo() {
  280. return deptNo;
  281. }
  282.  
  283. public void setDeptNo(String deptNo) {
  284. this.deptNo = deptNo;
  285. }
  286.  
  287. @Column(name = "DEPT_NAME", nullable = false)
  288. public String getDeptName() {
  289. return deptName;
  290. }
  291.  
  292. public void setDeptName(String deptName) {
  293. this.deptName = deptName;
  294. }
  295.  
  296. @Column(name = "LOCATION")
  297. public String getLocation() {
  298. return location;
  299. }
  300.  
  301. public void setLocation(String location) {
  302. this.location = location;
  303. }
  304.  
  305.  
  306. }
  307.  
  308. <?xml version="1.0"?>
  309. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  310. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  311. <!-- Generated Apr 12, 2016 12:33:11 AM by Hibernate Tools 3.5.0.Final -->
  312. <hibernate-mapping>
  313. <class name="com.entities.Department" table="DEPARTMENT">
  314. <id name="deptId" type="int">
  315. <column name="DEPTID" />
  316. <generator class="assigned" />
  317. </id>
  318. <property name="deptNo" type="java.lang.String">
  319. <column name="DEPTNO" />
  320. </property>
  321. <property name="deptName" type="java.lang.String">
  322. <column name="DEPTNAME" />
  323. </property>
  324. <property name="location" type="java.lang.String">
  325. <column name="LOCATION" />
  326. </property>
  327. </class>
  328. </hibernate-mapping>
  329.  
  330. <?xml version="1.0" encoding="UTF-8"?>
  331. <!DOCTYPE hibernate-configuration PUBLIC
  332. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  333. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  334. <hibernate-configuration>
  335. <session-factory>
  336. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  337. <property name="hibernate.connection.password">ruoitrau95</property>
  338. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testdkt</property>
  339. <property name="hibernate.connection.username">root</property>
  340. <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
  341. </session-factory>
  342. </hibernate-configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement