私はこのガイドを春https://spring.io/guides/gs/batch-processing/から守っています。hsqlの代わりにspring use mysqlを作る方法
私はhsqlを使用している限りすべて動作しますが、mysqlに切り替える必要があります。問題は、Springは常にhsqlインスタンスを起動して使用しようとしていることです。
コードを以下に示します。hello.ressourcesで
application.properties:私のBatchConfigurationクラスで
spring.datasource.url=jdbc:mysql://xxx:3306/xxx
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
hello.ressourcesでdatasource.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://xxx:3306/xxx" />
<property name="username" value="user" />
<property name="password" value="pass" />
</bean>
</beans>
があり、 @Autowired
プロパティ
@Autowired
public DataSource dataSource;
Intelijはそれをdatasource.xml
に接続していると表示しています。しかし
、私は言ったアプリケーションそれ最初のログ表示されません
o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa'
し、エラーをスローを実行すると:
PreparedStatementCallback。悪いSQL文法[INSERT INTO people(first_name、last_name)VALUES(?、?)];ネストされた例外はjava.sql.SQLSyntaxErrorExceptionです:ユーザーが権限を持たないか、オブジェクトが見つかりません:私は、スキーマ-mysql.sqlにスキーマall.sqlを変更し、
DROP TABLE IF EXISTS people; CREATE TABLE people ( person_id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT , first_name VARCHAR(20), last_name VARCHAR(20) );
にコードを変更した
人々私のbuild.gradleでは、私は、ビルドの依存関係に
classpath 'mysql:mysql-connector-java:5.1.6'
を追加したと
にコンパイルDEPSからHSQL一部を変更しましたcompile("mysql:mysql-connector-java:5.1.6")
ここでmysqlを使用し、hsqlを無効にするにはどうすればよいですか?
EDIT:
プロジェクト構造:http://imgur.com/HEuiw9W
私はdatasource.xmlを削除しました。
これはbuild.gradleです:あなたが撮った
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE")
classpath 'mysql:mysql-connector-java:5.1.6'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-batch-processing'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-batch")
compile("mysql:mysql-connector-java:5.1.6")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
@Jarrodrobersonあなたがこれを閉じるために投票した質問は、クラスがないことに関するものでした。私はそうではありません。 –
今、この質問はリンクされたものの複製ではありません。どちらもHSQLからMySQLに切り替える予定ですが、これはSpringBootプロジェクトであり、デフォルトでBootは組み込みHSQLをデータベースとして構成します。この質問は重複している可能性がありますが、リンクされた質問は間違いなく1つです –
この@AliDehghaniを修正する方法がありますか –