Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Qualifier to force bean dependency #3098

Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private static ObjectMapper createDefaultEndpointMapper(
*/
@Bean
EndpointInvoker endpointInvoker(ApplicationContext applicationContext,
ObjectMapper hillaEndpointObjectMapper,
@Qualifier("hillaEndpointObjectMapper") ObjectMapper hillaEndpointObjectMapper,
ExplicitNullableTypeChecker explicitNullableTypeChecker,
ServletContext servletContext, EndpointRegistry endpointRegistry) {
return new EndpointInvoker(applicationContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.vaadin.hilla.signals.core.registry.SecureSignalsRegistry;
import com.vaadin.hilla.signals.handler.SignalsHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand All @@ -37,7 +38,7 @@ public class SignalsConfiguration {
private final EndpointInvoker endpointInvoker;

public SignalsConfiguration(EndpointInvoker endpointInvoker,
ObjectMapper hillaEndpointObjectMapper) {
@Qualifier("hillaEndpointObjectMapper") ObjectMapper hillaEndpointObjectMapper) {
this.endpointInvoker = endpointInvoker;
Signal.setMapper(hillaEndpointObjectMapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.JacksonProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
Expand All @@ -25,9 +26,32 @@ public class EndpointControllerConfigurationTest {
@Autowired
private EndpointAccessChecker endpointAccessChecker;

@Autowired
private ConfigurableApplicationContext context;

@Test
public void dependenciesAvailable() {
Assert.assertNotNull(endpointRegistry);
Assert.assertNotNull(endpointAccessChecker);
}

@Test
public void testEndpointInvokerUsesQualifiedObjectMapper()
throws NoSuchFieldException, IllegalAccessException {
var endpointInvoker = context.getBean(EndpointInvoker.class);
var objectMapper = context.getBean("hillaEndpointObjectMapper");

Assert.assertNotNull("EndpointInvoker should not be null",
endpointInvoker);
Assert.assertNotNull("hillaEndpointObjectMapper should not be null",
objectMapper);

var field = EndpointInvoker.class
.getDeclaredField("endpointObjectMapper");
field.setAccessible(true);

Assert.assertSame(
"EndpointInvoker should use the qualified hillaEndpointObjectMapper",
objectMapper, field.get(endpointInvoker));
}
}
Loading