0

我试图在我的应用程序中使用休眠,但是它抛出了一个异常。以下是我尝试运行它时的堆栈跟踪。当我尝试用简单的 java 连接时,它工作正常。

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")
java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
java.security.AccessController.checkPermission(AccessController.java:559)
java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:611)
java.lang.ClassLoader.checkCreateClassLoader(ClassLoader.java:275)
java.lang.ClassLoader.<init>(ClassLoader.java:317)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.<init>(ClassLoaderServiceImpl.java:179)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.<init>(ClassLoaderServiceImpl.java:175)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.<init>(ClassLoaderServiceImpl.java:109)
org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:241)
org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
   org.geeksngeeks.database.ConnectionManager.init(ConnectionManager.java:43)
org.geeksngeeks.config.InitConfig.triggerAppStartup(InitConfig.java:252)

以下是我连接到数据库的代码。

Properties props = new Properties();

try {
  ResourceBundle rb = ResourceBundle.getBundle("hibernate");
  for (final Object name : rb.keySet()) {
    final String sName = String.valueOf(name);
    props.setProperty(sName.toLowerCase(), rb.getString(sName));
  }
} catch (Exception ex) {
  props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
  props.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
  props.setProperty("hibernate.connection.url", "jdbc:mysql://mysql-dev-01.cloud.wso2.com:3306/my_db_name");
  props.setProperty("hibernate.connection.username", "user");
  props.setProperty("hibernate.connection.password", "paswd");
  props.setProperty("hibernate.hbm2ddl.auto", "update");
}
Configuration configuration = new Configuration();
configuration.configure(new URL(Config.getWebserver() + "hibernate.cfg.xml"));
//configuration.setProperties(props);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().
    applySettings(configuration.getProperties()).build();

factory = configuration.buildSessionFactory(serviceRegistry);
4

2 回答 2

0

事实上,安全管理器正在阻止负载。如果您提交请求, WSO2 Cloud应该能够为您启用 Hibernate:只需登录 WSO2 App Cloud 并单击支持/联系我们以发送请求。

于 2015-05-02T00:24:05.757 回答
0

根据这条线:

java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:611)

您的 Java 进程启用了一些安全策略。至少可以肯定的是:

permission java.lang.RuntimePermission "createClassLoader";

您需要禁用此设置,否则将不允许您的应用程序实例化新的类加载器,而且它显然需要这样做。

于 2015-05-01T07:37:12.453 回答