我有一个第三方jar包,其中包含所有的实体和映射关系。我目前在一个传统的Spring-MVC应用程序中成功使用这个jar包,但现在我正在尝试在一个Spring-Boot应用程序中使用它。(1.5.7.RELEASE)
这是我的Application.java文件:
@SpringBootApplication
@EntityScan(basePackages = "com.third.party.entity.package")
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
由于它是第三方,所以我必须进行会话扫描,因此我在我的@Configuration类中添加了以下内容:
@Bean
public LocalSessionFactoryBean sessionFactory(EntityManagerFactory emf) throws ClassNotFoundException {
LocalSessionFactoryBean fact = new LocalSessionFactoryBean();
fact.setAnnotatedPackages("com.third.party.entity.package");
fact.setPackagesToScan("com.third.party.entity.package");
fact.setDataSource(dataSource);
return fact;
}
这是我的application.properties文件中的内容:
spring.datasource.url=jdbc:mysql://dbserver:3306/mydb?useSSL=false
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
我正在遇到这个错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mydb.user' doesn't exist
现在表名为“User”,这有点说得通。但是,我正在为另一个应用程序使用此jar文件,因此所有其他100个关于此主题的答案均不适用。
这一定是配置问题了吧?对吗?
更新 我尝试了下面@sam的回答,但没有成功,但我能够查看此第三方jar文件的源代码,它看起来像这样:
@Entity
@Table(name = "User")
public class User {
etc...
}
因此,注释中的表名是正确的。我该如何让Spring使用它?我正在查找默认命名策略之类的东西... 有什么建议吗?