问题是我的连接URL似乎是真实的,但无法连接到服务器,我正在检查另一种Java应用程序,它运行得很好,但是在春季,mvc不连接。我正在使用doma。问题说
我在github上的项目:https://github.com/chickenoken/LuanAn
[DOMA2048]コネクションを取得しようとしましたが失败しました。トランザクションが开始されていません
表示无法连接数据库。我正在检查网址是jdbc:sqlserver://localhost:1433;databaseName=NetDatabase
我所缺少的
AppConfig.java
@SingletonConfig
@Transactional
@Component
@Repository
public class AppConfig extends DomaAbstractConfig {
private static final String JDBC_FILE = "datasource-cfg.properties";
private static final String URL = "jdbc.sqlServer.url";
private static final String USER = "jdbc.sqlServer.user";
private static final String PASSWORD = "jdbc.sqlServer.password";
private static final String DATABASE_NAME = "jdbc.sqlServer.databaseName";
static {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
protected static final LocalTransactionalDataSource dataSource = createDataSource();
protected static final Dialect dialect = new MssqlDialect();
@Override
public DataSource getDataSource() {
return dataSource;
}
@Override
public Dialect getDialect() {
return dialect;
}
protected static LocalTransactionalDataSource createDataSource() {
Properties prop = new Properties();
try {
prop.load(ClassName.class.getClassLoader().getResourceAsStream(JDBC_FILE));
} catch (IOException e) {
e.printStackTrace();
}
String url = prop.getProperty(URL);
String user = prop.getProperty(USER);
String password = prop.getProperty(PASSWORD);
String databaseName = prop.getProperty(DATABASE_NAME);
String connection = url + ";" + "databaseName=" + databaseName;
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setUrl(connection);
dataSource.setUser(user);
dataSource.setPassword(password);
return new LocalTransactionalDataSource(dataSource);
}
public static LocalTransaction getLocalTransaction() {
return dataSource.getLocalTransaction(defaultJdbcLogger);
}
}
datasource-cfg.properties
jdbc.sqlServer.driver =com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.sqlServer.url =jdbc:sqlserver://localhost:1433
jdbc.sqlServer.databaseName =NetDatabase
jdbc.sqlServer.user =ccc
jdbc.sqlServer.password =1