Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello everyone, please I can't get SpringMVC project to create a table in MySql database. My entity class is below.
@Entity
@Table(name="customer")
@Data
@NoArgsConstructor
public class Customer {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	private String firstName;
	private String lastName;
	private String email;
	
}


This is my application.properties file.

spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp

#Setting the contextPath for the application
server.servlet.context-path=/CRM

#DataSource configuration(hikaricp)
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql:///javafullstack
spring.datasource.username = root
spring.datasource.password = root

#JPA -hibernate properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.generate-ddl=true

My application.properties is under src/main/resources and my jsp files are under src/main/WEB-INF/pages, please what I'm I missing ? Thanks for any help.

What I have tried:

The code complied without any error but the table is not created in the database.
Posted

1 solution

I've resolved this issue, start.spring.io created a package for the main class where the SpringApplication.run method is and I created my other packages on the same level as the package where the main class was instead of creating them directly as sub-packages under that package that start.spring.io created. Apparently was happens is that @ComponentScan detects packages the are sub-packages of the main class to create/register the Spring managed components and since my other packages (services, model, dao, restcontroller) were not directly under the main class's package, Spring couldn't detect them, that's why the table wasn't created in the DB. I hope this might help someone someday.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900