我试图在我的应用程序中使用休眠,但是它抛出了一个异常。以下是我尝试运行它时的堆栈跟踪。当我尝试用简单的 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);