下面是我对数据源的JNDI查找
<bean id="datasource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/intdb" />
</bean>
和flyway bean配置
<bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="dataSource" ref="datasource" />
</bean>
我得到的是异常,但如果我用bean中的所有属性替换JNDI查找它可以正常工作,
引起:org.flywaydb.core.api.FlywayException:同时出错 确定数据库产品名称 at org.flywaydb.core.internal.dbsupport.DbSupportFactory.getDatabaseProductName(DbSupportFactory.java:139) 在org.flywaydb.core.internal.dbsupport.DbSupportFactory.createDbSupport(DbSupportFactory.java:59) 在org.flywaydb.core.Flyway.execute(Flyway.java:1147) 在org.flywaydb.core.Flyway.migrate(Flyway.java:811) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ......还有26个 引起:java.sql.SQLException:不支持的功能 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179) at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269) at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689) at oracle.jdbc.OracleDatabaseMetaData.getDatabaseMajorVersion(OracleDatabaseMetaData.java:4442) 在org.flywaydb.core.internal.dbsupport.DbSupportFactory.getDatabaseProductName(DbSupportFactory.java:134)
答案 0 :(得分:1)
我的项目中有类似的,工作配置。在Spring上下文XML中我得到了:
<bean id="migrationDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/myTestDb"/>
</bean>
<bean id="dbMigrationManager" class="test.version.DbMigrationManager" init-method="updateDatabaseSchema">
<constructor-arg name="migrationDataSource" ref="migrationDataSource"/>
</bean>
我通过DbMigrationManager中的构造函数参数包装数据源。它看起来像这样:
package test.version;
import org.flywaydb.core.Flyway;
import javax.sql.DataSource;
public class DbMigrationManager {
private final DataSource dataSource;
public DbMigrationManager(DataSource migrationDataSource) {
this.dataSource = migrationDataSource;
}
public void updateDatabaseSchema() {
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.migrate();
}
}
此外,我正在gradle中使用Flyway 3.0版本:
compile group: 'org.flywaydb', name: 'flyway-core', version: '3.0'
如果这没有帮助,那么您的问题可能是特定于数据库的。就像在这个帖子中一样:
Exception against Oracle DB: "Error while determining database product name: Unsupported feature"
或者你正在使用一些较旧的,错误的Flyway版本。