I am new to the Spring environment. I was trying to develop a basic MVC application using SpringBoot with Hibernate as ORM and MYSQL as database. I ran into lots of troubles setting-up the dependencies and the configurations. Currently, I was struck on the following error and I was not able to figure out how to get over it.
org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
This is the set-up that I have in my application. It has no service layer and jsp pages to avoid the clutter
DATABASE:
MySql - A Database called Users is already present and it has a table called Users with a sample list of users
User.java(Model)
@Entity
@Table(name = "Users")
public class User {
@Id
@GeneratedValue
public String id;
public String username;
public String firstname;
public String lastname;
public String password;
}
UserRepository:
@Repository
@Table(name = "Users")
public interface UserRepository extends JpaRepository<User, String> {
}
UserController:
@RestController
public class UserController {
private UserRepository userRepository;
@Autowired
public UserController(UserRepository userRepository)
{
this.userRepository = userRepository;
}
@RequestMapping("user")
public void getUser(@RequestParam("id") String id) {
User user = userRepository.findOne(id);
}
}
Application.properties:
server.port: 9000
spring.datasource.url: jdbc:mysql://localhost/Users
spring.datasource.driverClassName: com.mysql.jdbc.Driver
spring.datasource.username: root
spring.datasource.password:
POM.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- HIBERNATE -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.0.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring ORM, works with Hibernate -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
EDIT: Adding the main class
MAIN CLASS
@ComponentScan
@Configuration
@EnableAutoConfiguration
public class ApplicationStart {
public static void main(String[] args)
{
SpringApplication.run(ApplicationStart.class, args);
}
}
This is the current setup of my application. I don't even seem to know where to look for errors and the tutorials in the internet did not help my cause. So, any help on how to resolve the exception is much appreciated.
Please comment if more information is required.
Thanks-
application.properties
file. Make sure it is in the root of the class path (src/main/resources
) or when on the file system next to your jar. In general you separate key/value pairs in a property file with=
instead of:
although the latter should work. I also don't really get your setup simply remove the exclude for hibernate and only includehibernate-entitymanager
without a version as a dependency. Everything else will be taken care of. – M. Deinumjava.lang.IllegalArgumentException: Not an managed type: class models.User
And, my application.properties is in the resources directory. – BalasubramanianEnableAutoConfiguration
is trying to figure out which packages to scan for entities based on the package it is in. You might want to add a@EntityScan
pointing to the package which contain your entity classes. Also note theComponentScan
will scan starting from the same package theApplicationStart
class is in. Maybe you can include your package structure in the post. – M. Deinum