Skip to content

Commit d4fc77f

Browse files
authored
GH-1467: Support Spring AOT for Native Image
Resolves #1467 Migrate proxy hints from spring-native. Also add a proxy hint for `ChannelProxy` when it is also a `PublisherCallbackChannel`.
1 parent 32c1c99 commit d4fc77f

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.amqp.rabbit.aot;
18+
19+
import org.springframework.amqp.rabbit.annotation.RabbitListener;
20+
import org.springframework.amqp.rabbit.connection.ChannelProxy;
21+
import org.springframework.amqp.rabbit.connection.PublisherCallbackChannel;
22+
import org.springframework.aop.SpringProxy;
23+
import org.springframework.aop.framework.Advised;
24+
import org.springframework.aot.hint.ProxyHints;
25+
import org.springframework.aot.hint.RuntimeHints;
26+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
27+
import org.springframework.aot.hint.TypeReference;
28+
import org.springframework.aot.hint.support.RuntimeHintsUtils;
29+
import org.springframework.core.DecoratingProxy;
30+
import org.springframework.lang.Nullable;
31+
32+
/**
33+
* {@link RuntimeHintsRegistrar} for spring-rabbit.
34+
*
35+
* @author Gary Russell
36+
* @since 3.0
37+
*
38+
*/
39+
public class RabbitRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
40+
41+
@Override
42+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
43+
RuntimeHintsUtils.registerAnnotation(hints, RabbitListener.class);
44+
ProxyHints proxyHints = hints.proxies();
45+
proxyHints.registerJdkProxy(ChannelProxy.class);
46+
proxyHints.registerJdkProxy(ChannelProxy.class, PublisherCallbackChannel.class);
47+
proxyHints.registerJdkProxy(builder ->
48+
builder.proxiedInterfaces(TypeReference.of(
49+
"org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer$ContainerDelegate"))
50+
.proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class));
51+
}
52+
53+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Provides classes to support Spring AOT.
3+
*/
4+
@org.springframework.lang.NonNullApi
5+
@org.springframework.lang.NonNullFields
6+
package org.springframework.amqp.rabbit.aot;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.amqp.rabbit.aot.RabbitRuntimeHintsRegistrar

0 commit comments

Comments
 (0)