本文整理汇总了Java中com.alibaba.dubbo.config.spring.ServiceBean.getSpringContext方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceBean.getSpringContext方法的具体用法?Java ServiceBean.getSpringContext怎么用?Java ServiceBean.getSpringContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.config.spring.ServiceBean
的用法示例。
在下文中一共展示了ServiceBean.getSpringContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import com.alibaba.dubbo.config.spring.ServiceBean; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Status check() {
ApplicationContext context = ServiceBean.getSpringContext();
if (context == null) {
return new Status(Status.Level.UNKNOWN);
}
Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
if (dataSources == null || dataSources.size() == 0) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
DataSource dataSource = entry.getValue();
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(entry.getKey());
try {
try (Connection connection = dataSource.getConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
try (ResultSet resultSet = metaData.getTypeInfo()) {
if (!resultSet.next()) {
level = Status.Level.ERROR;
}
}
buf.append(metaData.getURL());
buf.append("(");
buf.append(metaData.getDatabaseProductName());
buf.append("-");
buf.append(metaData.getDatabaseProductVersion());
buf.append(")");
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
return new Status(level, e.getMessage());
}
}
return new Status(level, buf.toString());
}
示例2: check
import com.alibaba.dubbo.config.spring.ServiceBean; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Status check() {
ApplicationContext context = ServiceBean.getSpringContext();
if (context == null) {
return new Status(Status.Level.UNKNOWN);
}
Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
if (dataSources == null || dataSources.size() == 0) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
DataSource dataSource = entry.getValue();
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(entry.getKey());
try {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getTypeInfo();
try {
if (! resultSet.next()) {
level = Status.Level.ERROR;
}
} finally {
resultSet.close();
}
buf.append(metaData.getURL());
buf.append("(");
buf.append(metaData.getDatabaseProductName());
buf.append("-");
buf.append(metaData.getDatabaseProductVersion());
buf.append(")");
} finally {
connection.close();
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
return new Status(level, e.getMessage());
}
}
return new Status(level, buf.toString());
}
示例3: check
import com.alibaba.dubbo.config.spring.ServiceBean; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Status check() {
ApplicationContext context = ServiceBean.getSpringContext();
if (context == null) {
return new Status(Status.Level.UNKNOWN);
}
Map<String, DataSource> dataSources = context.getBeansOfType(DataSource.class, false, false);
if (dataSources == null || dataSources.size() == 0) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
StringBuilder buf = new StringBuilder();
for (Map.Entry<String, DataSource> entry : dataSources.entrySet()) {
DataSource dataSource = entry.getValue();
if (buf.length() > 0) {
buf.append(", ");
}
buf.append(entry.getKey());
try {
Connection connection = dataSource.getConnection();
try {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet resultSet = metaData.getTypeInfo();
try {
if (!resultSet.next()) {
level = Status.Level.ERROR;
}
} finally {
resultSet.close();
}
buf.append(metaData.getURL());
buf.append("(");
buf.append(metaData.getDatabaseProductName());
buf.append("-");
buf.append(metaData.getDatabaseProductVersion());
buf.append(")");
} finally {
connection.close();
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
return new Status(level, e.getMessage());
}
}
return new Status(level, buf.toString());
}