我正在尝试使用 openfire 运行 Spring,但出现此错误: FileNotFoundException: 类路径资源 [ForwarderApplicationConfiguration.class] 无法打开,因为它不存在 org.springframework.context.annotation.ConfigurationClassParser - 无法通过 ASM 读取类文件用于确定@Bean 方法顺序
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ForwarderApplicationConfiguration {
private static final Logger LOGGER = LoggerFactory.getLogger(ForwarderApplicationConfiguration.class);
public final static String QUEUE_NAME = "shout_forwarder";
@Bean
public Channel channel() {
LOGGER.info("Initializing Forwarding Plugin");
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("192.168.100.122");
factory.setPassword("password");
factory.setUsername("publisher");
try {
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
return channel;
} catch (Exception ex) {
LOGGER.error("Initializing Forwarding Plugin \n" + ex.getMessage());
throw new RuntimeException(ex);
}
}
@Bean
public MessageInterceptor messageInterceptor(Channel channel) {
return new MessageInterceptor(channel);
}
}
这是主要课程:
import org.jivesoftware.openfire.MessageRouter;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.xmpp.packet.JID;
import java.io.File;
public class MessageForwarderPlugin implements Plugin {
private static final Logger Log = LoggerFactory.getLogger(MessageForwarderPlugin.class);
private final InterceptorManager interceptorManager;
private final JID violationNotificationFrom;
private final MessageRouter messageRouter;
private ApplicationContext springContext;
private MessageInterceptor messageInterceptor;
public MessageForwarderPlugin() {
interceptorManager = InterceptorManager.getInstance();
violationNotificationFrom = new JID(XMPPServer.getInstance()
.getServerInfo().getXMPPDomain());
messageRouter = XMPPServer.getInstance().getMessageRouter();
springContext = new AnnotationConfigApplicationContext(ForwarderApplicationConfiguration.class);
}
@Override
public void initializePlugin(PluginManager manager, File pluginDirectory) {
Log.info("Initializing Forwarding Plugin");
messageInterceptor = (MessageInterceptor) springContext.getBean("messageInterceptor");
interceptorManager.addInterceptor(messageInterceptor);
}
@Override
public void destroyPlugin() {
Log.info("Destroying Forwarding Plugin");
interceptorManager.removeInterceptor(messageInterceptor);
}
}
起居室:
<modelVersion>4.0.0</modelVersion>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>forwarder</artifactId>
<version>${maven.build.timestamp}</version>
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.7.3</version>
</dependency>
<dependency>
<groupId>com.cenqua.shaj</groupId>
<artifactId>shaj</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<parent>
<groupId>org.igniterealtime.openfire</groupId>
<artifactId>plugins</artifactId>
<version>4.2.0</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>5.2.7.RELEASE</spring.version>
<maven.build.timestamp.format>dd.HH.mm</maven.build.timestamp.format>
<dev.build.timestamp>${maven.build.timestamp}</dev.build.timestamp>
</properties>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.igniterealtime.openfire.plugins</groupId>
<artifactId>openfire-plugin-assembly-descriptor</artifactId>
<version>${openfire.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>true</appendAssemblyId>
<finalName>${plugin.name}</finalName>
<attach>true</attach>
<descriptorRefs>
<descriptorRef>openfire-plugin-assembly</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<name>Message Forwarder Plugin</name>
<description>A start point to create a new plugin</description>