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

xml websockets configuration does not mirror annotation configuration [SPR-15068] #19634

Closed
spring-issuemaster opened this issue Dec 29, 2016 · 5 comments

Comments

@spring-issuemaster
Copy link
Collaborator

commented Dec 29, 2016

Jordan Glassman opened SPR-15068 and commented

The websockets docs refer to a bean named "brokerMessagingTemplate", that I am unable to instantiate using the XML-based configuration.

2016-12-29 14:16:35.364  WARN 41570 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'restResource' defined in file [/Users/me/Downloads/demo/build/classes/main/com/example/RestResource.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.messaging.simp.SimpMessagingTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=brokerMessagingTemplate)}

Injecting this type without the qualifier or creating a bean of type SimpMessagingTemplate succeeds but does not share configuration with whatever other classes are created for the websockets message broker, eg. it cannot find see open websockets. A call to #convertAndSend results in:

2016-12-29 13:44:40,580 DEBUG :clientInboundChannel-5 [][org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler] Processing SUBSCRIBE /topic/test id=0 session=0cd15c1fd7e249e18f19dafce77b815b
....
2016-12-29 13:44:40,622 DEBUG :http-nio-8080-exec-1 [][org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler] Processing MESSAGE destination=/topic/test session=null payload=body

Sample project with both configurations (one commented out) attached.


Affects: 4.3 GA

Reference URL: http://stackoverflow.com/questions/37294525/spring-websockets-xml-configuration-not-providing-brokermessagingtemplate

Attachments:

Referenced from: commits 75daf78, 2e414ab

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 3, 2017

Rossen Stoyanchev commented

The XML namespace does create a SimpMessagingTemplate that sends to the "brokerChannel", which is then used for sending messages from the return values of annotated controller methods. We are not however giving the explicit name "brokerMessagingTemplate" which is why the qualifier doesn't work. We'll correct that.

That said if you inject without the qualifier it should work. Or even with your own SimpMessagingTemplate it should. I haven't run the sample yet but from a quick look at the output above I don't see what's wrong. Messages sent from within the (server-side) application will have a null, this is expected.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 3, 2017

Jordan Glassman commented

When I tried without the qualifier, the result was the log above:

2016-12-29 13:44:40,622 DEBUG :http-nio-8080-exec-1 [][org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler] Processing MESSAGE destination=/topic/test session=null payload=body

as opposed to the successful case, using Java config:

2017-01-03 15:53:05,641 DEBUG :websocket-1 [][org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler] Processing MESSAGE destination=/topic/test-usere4de7fc09c3641a5b7f2b198c866dd5a session=null payload=body

My debugging suggested that the UserRegistry in the UserDestinationResolver was not getting initialized.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 3, 2017

Rossen Stoyanchev commented

What destination exactly are you sending to, "/topic/test"? I wouldn't expect that to be turned into a user destination which by default should have a "/user" prefix, so I need more context. I looked at the attached code which has a SimpMessagingTemplate injected into a @RestController but it's not used.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 5, 2017

Jordan Glassman commented

Confirmed that the unqualified injection works for both the XML and annotation config cases.

I now believe the failure referenced above was an unrelated problem associated with my security configuration.

End-to-end POC attached for posterity.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 5, 2017

Rossen Stoyanchev commented

Okay thanks for confirming so we'll just give it the same well-known bean name then in the XML namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.