java第六天/10.14

本文详细介绍了Java中的封装概念及其实现方式,包括private修饰符的使用、this关键字的意义和应用,以及静态方法和成员变量的特点。通过具体示例展示了如何通过封装提高代码的安全性和维护性。

一、匿名对象
定义:没有名字的对象。
意义:节省代码,并且很多情况下是针对某个方法只需要调用一次的参数进行传递。
主要的作用就是节省代码量,是代码结构更优雅。
二、封装
1、概念:隐藏对象的属性和细节,仅对外提供公共的方法进行访问。
2、private

a、当类的成员变量使用private修饰符修饰,那么就不可以直接访问到该成员变量。
b、当使用private修饰的成员变量或者成员方法,仅能在本类中使用。
c、private对于main方法的修饰,也是可以使用的。
例:
package _01.org.westos;
public class DemoPrivate {
public static void main(String[] args){
Person4 person=new Person4();
person.name=”sunshine”;
person.setAge(20);
person.action();
}
}
class Person4{
String name;
private int age;
void setAge(int ageParm){
if(ageParm>0&&ageParm<150){
age=ageParm;
}
}
void eat(){
System.out.println(“eat”);
}
void action(){
eat();
speak();
}
void speak(){
System.out.println(“speak:”+name+” “+age);
}
}
这里写图片描述
javaBean
是这样一类的类:
他的所有成员变量都使用private进行修饰,并且对外提供可访问的设置值和获取值的set,get方法。不同的应用场景,可能命名不同。数据库的应用中成为POJO
类。
例:
package _01.org.westos;
public class DemoBean {
static void main(String[] args){
Person1 person = new Person1();
person.setName(“diffo”);
person.setAge(30);
person.speak();
}
}
class Person1{
private String name;
private int age;
void setName(String nameParm){
name = nameParm;
}
String getName(){
return name;
}
void setAge(int ageParm){
age = ageParm;
}
int getAge(){
return age;
}
void speak(){
System.out.println(name+” . “+age);
}这里写图片描述
}

main方法细节
a、每个类中都可以存在main方法,但是执行的时候,jvm会优先查看public的class中是否有main方法。
b、如果没有public的class,那么会按照文件名优先查找类中的main方法。
c、必须定义为public。

三、优先原则
对于一个类的成员方法来说,如果传递的形参变量名称和类的成员变量名称相同,jvm在处理的时候优先当做方法的形参来处理。
四、this 关键字
1、含义:
代表了当前对象的引用。
可以理解为,当前谁来调用,那么方法中的this就代表谁。
对于成员变量可以区分出来的场景,this可加也可不加,实际效果相同。
但是对于实现javaBean/POJO来说,我们建议都加上在setXxx,getXxx方法中。

this:可以加在成员变量的前边来指定对应的引用,也可以加在成员方法的前边。

五、初始化类成员变量的方式
a、在定义成员变量的同时赋值。
//在构造方法执行之前进行赋值,并且该类每个实现的对象,都会被初始化该值。
//意义:当我们需要一个类的所有对象某些成员变量的值一致的时候。

b、提供外界可访问到的方法,在方法中赋值。
//构造方法中直接赋值
//意义:可以在创建对象的同时进行赋值,同时还可以动态指定设定的值是什么

c、通过构造方法进行赋值
//通过调用某个设置值的方法进行赋值,在对象创建完成之后
//意义:动态的修改成员变量的值。

六、static
a、随着类加载而加载
静态方法区中来保存静态成员变量

b.优先于对象创建
Person.className = “java”;

c.被类的所有对象共享
静态的成员变量会保存在该class的静态方法区中,所以每个对象看到的都是同一份.

d.可以通过类名来访问也可以通过对象名来访问。
效果是一样的。

e.推荐通过类名来访问

f.静态的成员,一般称为类相关的成员。

g.static 修饰符既可以修饰成员变量,也可以修饰成员方法。 且修饰之后,就可以通过类名来直接访问到。

h.this变量在静态方法中不可以使用

i.静态方法中只能访问静态成员变量和静态方法。
非静态方法既可以访问静态成员和方法也可以访问非静态成员和方法。
非静态虽然可以访问静态的方法,但是不建议这样做。
七、main方法
修饰符 返回类型 方法名(参数列表){
}
public static void main(String[] args){
}
public:最大的一个访问权限,使得jvm能够成功调用
static:类相关的,与对象无关。A.main([]);

public class A{
main(){
System.out.println(“”);
}
}

void:不需要返回值
方法名:main
参数列表:执行的时候,可以传递参数。
八、工具类
全部都是静态的方法。所以可以通过 类名.functionName() 方式来访问。
一般的话,都会对默认构造方法进行私有化处理,来防止别人使用时习惯性的创建对象来调用方法。
例:
package _01.org.westos;
public class ClassTestFinal {
public static void main(String[] args){
Square square=new Square();
square.setLength(3);
System.out.println(SquareUtil.getCircumLength(square));
System.out.println(SquareUtil.getArea(square));
}
}
//POJO类
class Square{
private int length;
void setLength(int length){
this.length=length;
}
int getLength(){
return this.length;
}
}
//正方形工具类
class SquareUtil{
private SquareUtil(){
}
static int getCircumLength(Square square){
return 4*square.getLength();
}
static int getArea(Square square){
return square.getLength()*square.getLength();
}
}
这里写图片描述

[root@yfw ~]# cd /opt/openfire [root@yfw openfire]# sudo systemctl stop openfire [root@yfw openfire]# ps aux | grep openfire | grep -v grep [root@yfw openfire]# rm -f /opt/openfire/logs/openfire.pid [root@yfw openfire]# ss -tulnp | grep ':9090\|:5222' [root@yfw openfire]# sudo systemctl start openfire [root@yfw openfire]# tail -f /opt/openfire/logs/nohup.out at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ~[xmppserver-5.0.2.jar:5.0.2] ... 11 more 启动服务器时出错。有关详细信息,请查看日志件。 Halting server... Server halted 16:25:21.035 [main] ERROR org.jivesoftware.database.DbConnectionManager - Failed to create database '/opt/openfire/embedded-db', see the next exception for details. java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.EmbedConnection.createDatabase(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver$1.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver$1.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?] at org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.sql.DriverManager.getConnection(DriverManager.java:681) ~[java.sql:?] at java.sql.DriverManager.getConnection(DriverManager.java:252) ~[java.sql:?] at org.apache.commons.dbcp2.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:119) ~[commons-dbcp2-2.9.0.jar:2.9.0] at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:374) ~[commons-dbcp2-2.9.0.jar:2.9.0] at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:918) ~[commons-pool2-2.9.0.jar:2.9.0] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:431) ~[commons-pool2-2.9.0.jar:2.9.0] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:356) ~[commons-pool2-2.9.0.jar:2.9.0] at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:141) ~[commons-dbcp2-2.9.0.jar:2.9.0] at org.jivesoftware.database.DefaultConnectionProvider.getConnection(DefaultConnectionProvider.java:88) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.setConnectionProvider(DbConnectionManager.java:656) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.ensureConnectionProvider(DbConnectionManager.java:101) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:162) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.loadProperties(JiveProperties.java:472) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.init(JiveProperties.java:108) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.getInstance(JiveProperties.java:84) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getProperty(JiveGlobals.java:547) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.cache.CacheFactory.<clinit>(CacheFactory.java:102) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:381) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Caused by: org.apache.derby.iapi.error.StandardException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source) ~[derby-10.14.2.0.jar:?] ... 41 more Caused by: org.apache.derby.iapi.error.StandardException: Directory /opt/openfire/embedded-db already exists. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.StorageFactoryService$10.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?] at org.apache.derby.impl.services.monitor.StorageFactoryService.createServiceRoot(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.BaseMonitor.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.FileMonitor.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.iapi.services.monitor.Monitor.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.EmbedConnection$5.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?] at org.apache.derby.impl.jdbc.EmbedConnection.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] ... 38 more 16:25:23.579 [main] ERROR org.jivesoftware.util.JiveProperties - ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.loadProperties(JiveProperties.java:472) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.init(JiveProperties.java:108) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.getInstance(JiveProperties.java:84) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getProperty(JiveGlobals.java:547) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.cache.CacheFactory.<clinit>(CacheFactory.java:102) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:381) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Database setup or configuration error: Please verify your database settings and check the logs/openfire.log file for detailed error messages. 16:25:26.205 [main] ERROR org.jivesoftware.openfire.XMPPServer - Database could not be accessed java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] java.lang.IllegalArgumentException: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1020) at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) at java.base/java.lang.Class.newInstance(Class.java:645) at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ... 11 more 16:25:26.206 [main] ERROR org.jivesoftware.openfire.XMPPServer - java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. java.lang.IllegalArgumentException: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1020) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ~[xmppserver-5.0.2.jar:5.0.2] ... 11 more 启动服务器时出错。有关详细信息,请查看日志文件。 tail: /opt/openfire/logs/nohup.out: file truncated 16:25:27.771 [main] ERROR org.jivesoftware.util.JiveGlobals - Unable to load default Openfire properties from: /opt/openfire/conf/openfire.xml java.io.IOException: XML properties file must be writable: openfire.xml at org.jivesoftware.util.XMLProperties.<init>(XMLProperties.java:156) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.loadOpenfireProperties(JiveGlobals.java:1276) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getXMLProperty(JiveGlobals.java:308) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:367) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Openfire 5.0.2 [2025年11月15日 下午4:25:27] 管理控制台正在侦听 http://124.71.230.244:9090 Halting server... Server halted Halting server... Server halted 16:25:39.285 [main] ERROR org.jivesoftware.database.DbConnectionManager - Failed to create database '/opt/openfire/embedded-db', see the next exception for details. java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.EmbedConnection.createDatabase(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver$1.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver$1.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?] at org.apache.derby.jdbc.InternalDriver.getNewEmbedConnection(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.sql.DriverManager.getConnection(DriverManager.java:681) ~[java.sql:?] at java.sql.DriverManager.getConnection(DriverManager.java:252) ~[java.sql:?] at org.apache.commons.dbcp2.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:119) ~[commons-dbcp2-2.9.0.jar:2.9.0] at org.apache.commons.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:374) ~[commons-dbcp2-2.9.0.jar:2.9.0] at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:918) ~[commons-pool2-2.9.0.jar:2.9.0] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:431) ~[commons-pool2-2.9.0.jar:2.9.0] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:356) ~[commons-pool2-2.9.0.jar:2.9.0] at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:141) ~[commons-dbcp2-2.9.0.jar:2.9.0] at org.jivesoftware.database.DefaultConnectionProvider.getConnection(DefaultConnectionProvider.java:88) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.setConnectionProvider(DbConnectionManager.java:656) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.ensureConnectionProvider(DbConnectionManager.java:101) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:162) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.loadProperties(JiveProperties.java:472) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.init(JiveProperties.java:108) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.getInstance(JiveProperties.java:84) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getProperty(JiveGlobals.java:547) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.cache.CacheFactory.<clinit>(CacheFactory.java:102) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:381) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Caused by: org.apache.derby.iapi.error.StandardException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source) ~[derby-10.14.2.0.jar:?] ... 41 more Caused by: org.apache.derby.iapi.error.StandardException: Directory /opt/openfire/embedded-db already exists. at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.StorageFactoryService$10.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?] at org.apache.derby.impl.services.monitor.StorageFactoryService.createServiceRoot(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.BaseMonitor.bootService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.BaseMonitor.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.services.monitor.FileMonitor.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.iapi.services.monitor.Monitor.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] at org.apache.derby.impl.jdbc.EmbedConnection$5.run(Unknown Source) ~[derby-10.14.2.0.jar:?] at java.security.AccessController.doPrivileged(AccessController.java:569) ~[?:?] at org.apache.derby.impl.jdbc.EmbedConnection.createPersistentService(Unknown Source) ~[derby-10.14.2.0.jar:?] ... 38 more 16:25:41.834 [main] ERROR org.jivesoftware.util.JiveProperties - ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.loadProperties(JiveProperties.java:472) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.init(JiveProperties.java:108) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveProperties.getInstance(JiveProperties.java:84) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getProperty(JiveGlobals.java:547) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.cache.CacheFactory.<clinit>(CacheFactory.java:102) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:381) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Database setup or configuration error: Please verify your database settings and check the logs/openfire.log file for detailed error messages. 16:25:44.521 [main] ERROR org.jivesoftware.openfire.XMPPServer - Database could not be accessed java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] java.lang.IllegalArgumentException: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1020) at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) at java.base/java.lang.Class.newInstance(Class.java:645) at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ... 11 more 16:25:44.522 [main] ERROR org.jivesoftware.openfire.XMPPServer - java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. java.lang.IllegalArgumentException: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1020) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:666) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Caused by: java.sql.SQLException: ConnectionManager.getConnection() failed to obtain a connection after 11 attempts. The exception from the last attempt is as follows: java.sql.SQLException: Failed to create database '/opt/openfire/embedded-db', see the next exception for details. at org.jivesoftware.database.DbConnectionManager.getConnection(DbConnectionManager.java:204) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.verifyDataSource(XMPPServer.java:1010) ~[xmppserver-5.0.2.jar:5.0.2] ... 11 more 启动服务器时出错。有关详细信息,请查看日志文件。 tail: /opt/openfire/logs/nohup.out: file truncated 16:25:45.770 [main] ERROR org.jivesoftware.util.JiveGlobals - Unable to load default Openfire properties from: /opt/openfire/conf/openfire.xml java.io.IOException: XML properties file must be writable: openfire.xml at org.jivesoftware.util.XMLProperties.<init>(XMLProperties.java:156) ~[xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.loadOpenfireProperties(JiveGlobals.java:1276) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.util.JiveGlobals.getXMLProperty(JiveGlobals.java:308) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.initialize(XMPPServer.java:367) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.start(XMPPServer.java:658) [xmppserver-5.0.2.jar:5.0.2] at org.jivesoftware.openfire.XMPPServer.<init>(XMPPServer.java:221) [xmppserver-5.0.2.jar:5.0.2] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) [?:?] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [?:?] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) [?:?] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) [?:?] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347) [?:?] at java.lang.Class.newInstance(Class.java:645) [?:?] at org.jivesoftware.openfire.starter.ServerStarter.start(ServerStarter.java:92) [startup.jar:5.0.2] at org.jivesoftware.openfire.starter.ServerStarter.main(ServerStarter.java:56) [startup.jar:5.0.2] Openfire 5.0.2 [2025年11月15日 下午4:25:45] 管理控制台正在侦听 http://ecs-124-71-230-244.compute.hwclouds-dns.com:9090 Halting server...
最新发布
11-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值