Я новичок в весенней загрузке. Я написал очень простой релаксирующий проект для выполнения действий CRUD над сущностью, и я использую jpa и sql server. Когда я его запускаю, происходит сбой, и ошибка связана с базой данных и драйвером.
Я прочитал почти все вопросы, связанные с этой ошибкой, и ни один из них не был ответом.
Вот вся информация:
application.properties:
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=restful;integratedSecurity=true
spring.datasource.initialize=true
spring.jpa.database=SQL_SERVER
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = create-drop
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myweb</groupId>
<artifactId>restful-api</artifactId>
<version>1.0-SNAPSHOT</version>
<name>restful-api</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jdbc -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
UserDaoImp.java:
@Repository
@Transactional
public class UserDaoImp implements UserDao {
@Autowired
private JdbcTemplate jt;
@Override
public List<User> getUsers() {
String query = "select all from Users";
RowMapper<User> rm = new UserRowMapper();
return jt.query(query, rm);
}
@Override
public User getUser(long id) {
String query = "select * from Users where Users.ID=?";
RowMapper<User> rm = new UserRowMapper();
return jt.queryForObject(query, rm, id);
}
@Override
public User getUser(String name, String lastName) {
String query = "select * from Users where Users.Name=? and Users.LastName=?";
RowMapper<User> rm = new UserRowMapper();
return jt.queryForObject(query, rm, name, lastName);
}
@Override
public void addUser(User user) {
if (!doesUserExist(user)) {
String query = "insert into Users values(?,?,?);";
jt.update(query, user.getName(), user.getLastName(), user.getId());
}
}
@Override
public void deleteUser(User user) {
String query = "Delete from Users where Users.id=? And Users.Name=? And Users.LastName=?";
jt.update(query, user.getId(), user.getName(), user.getLastName());
}
@Override
public void updateUser(User user) {
if (doesUserExist(user)) {
String query = "Update Users set Name=?, LastName=? where Users.Id=?";
jt.update(query, user.getName(), user.getLastName(), user.getId());
}
}
@Override
public boolean doesUserExist(User user) {
String query = "select * from Users where Users.Id=? And Users.Name=? And Users.LastName=?";
RowMapper<User> rm = new UserRowMapper();
User u = jt.queryForObject(query, rm, user.getId(), user.getName(), user.getLastName());
if (u == null) {
return false;
} else {
return true;
}
}
}
ServiceImp.java:
@org.springframework.stereotype.Service
public class ServiceImp implements Service {
@Autowired
private UserDaoImp udi;
@Override
public List<User> getUsers() {
return udi.getUsers();
}
@Override
public User getUser(long id) {
return udi.getUser(id);
}
@Override
public void addUser(User user) {
udi.addUser(user);
}
@Override
public void deleteUser(User user) {
udi.deleteUser(user);
}
@Override
public void update(User user) {
udi.updateUser(user);
}
}
Исключение:
Exception encountered during context initialization - cancelling refresh attempt: 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
в конце написано:
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Примечание: одна вещь, которую я не могу понять, это то, что я зарегистрировал зависимость для драйвера сервера sql в pom.xml , но библиотека не существует в External Library .
Привет