【问题标题】:Use mysql instead hsql java spring使用 mysql 代替 hsql java spring
【发布时间】:2016-07-07 21:02:23
【问题描述】:

我有这个代码,我使用 application.properties 来使用 mysql,但仍然使用 hsql。

application.properties

spring.datasource.url=jdbc:mysql://localhost:3307/dvv
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.platform=mysql

和应用程序.class

@EnableAutoConfiguration
@EnableJpaRepositories(basePackageClasses = {VideoRepository.class, VideoRepository2.class})
@Configuration
@EnableWebMvc
@ComponentScan



public class Application {

    // Tell Spring to launch our app!
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        }   

}

和存储库

@Repository
public interface VideoRepository2 extends CrudRepository<Video2, Long>{

    // Find all videos with a matching title (e.g., Video.name)
    public Collection<Video2> findByName(String title);

    // Find all videos within a given category
    public Collection<Video2> findByCategory(String category);
}

【问题讨论】:

    标签: java mysql spring


    【解决方案1】:

    你能验证一下吗,

    1.检查有多少 application-XXX.properties 文件存在于您的应用程序中。

    2.检查您是否使用正确 配置文件来运行此应用程序。

    也分享你的 hsql 配置。

    【讨论】:

    • @SundararajGovindasamy tnx 为您提供帮助 :)。我的应用程序中只有一个 app.pro。我不明白你说的正确个人资料是什么。
    • @aliishabazii,如果您有 2 个属性文件,一个用于开发环境,另一个用于 QA 环境,例如 application-dev.properties 和 application-qa.properties。然后,您需要告诉服务器要加载哪个属性文件(或使用哪个配置文件)。您能检查一下您在应用程序中配置 hsql 的位置吗?
    【解决方案2】:

    确保将 mysql 连接器添加到您的 pom.xml /build.gradle

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 2016-09-08
      • 2012-04-24
      • 2011-12-10
      • 2020-05-15
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 2019-07-01
      相关资源
      最近更新 更多