I'm using spring boot 2.1.1 version and use #EnableWebFlux but I got some errors.
Errors are
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.reactive.config.DelegatingWebFluxConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalStateException: The Java/XML config for Spring MVC and Spring WebFlux cannot both be enabled, e.g. via #EnableWebMvc and #EnableWebFlux, in the same application
How can I fix this problem.
You can't have both Spring MVC and Spring WebFlux enabled in Spring SPR-16609
enabling MVC and WebFlux in the same application context which triggers a conflict
you can't have them in the same process currently.
It offers a workaround to use use reactive repositories:
However, you can use reactive repositories from your existing Spring MVC application, and return the reactive types (Flux or Mono), from Spring MVC controller methods.
Based on Spring Docs and SpringFramework Collaborator Juergen Hoeller, you can have both Spring MVC and Spring WebFlux present in the same app. In this way, you are using Spring MVC by default, while you can have reactively enabled endpoints at the same time. Keep in mind, it is essentially a servlet-based MVC app you are using.
If you also have #EnableWebFlux on top of that, you mean that you wish to strictly turn this into a reactive web application.
My suggestion is to turn off #EnableWebFlux and keep your application straightly MVC-based. You can still use some of the reactive features such as Mono<> and Flux<> by importing Webflux dependencies.
I was facing the same issue as using io.springfox with Spring-WebFlux.
I changed to use springdoc and solved the issue: https://springdoc.org/#migrating-from-springfox
For sample detail you can check in this: https://github.com/mnguyencntt/springboot-webflux-swagger
Related
I have a set of RestControllers in a spring reactive web project and I want to prefix all of the controllers with "api" or "test-api" in different environments.
I have tried to use server.servlet.context-path=/api and it's not working with spring reactive web (webflux) running on Netty server
The following property was added in spring boot 2.3 to achieve this with webflux
spring.webflux.base-path
Release Notes: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.3-Release-Notes#configurable-base-path-for-webflux-applications
Have you tried using a placeholders in #RequestMapping, like for example #RequestMapping("${foo.bar}") ?
Thank you
I am new to spring mvc and DI. I have came to know about the flow of the spring project and i know how the web projects in spring mvc is developed and worked on few projects too. All the annotation uses and xml configuration files in the spring mvc. But i am confused where the DI is used? and how the DI is implemented in spring with the help of IOC??
Can anyone please explain me the concept of DI and IOC and their implementation in spring mvc.
Thanks in advance!!!
DI and IOC happening through web.xml where you created the dispatcherservlet.
From Spring MVC docs :
The DispatcherServlet, provides a shared algorithm for request processing while actual work is performed by configurable, delegate components
The DispatcherServlet, as any Servlet, needs to be declared and mapped according to the Servlet specification using Java configuration or in web.xml. In turn the DispatcherServlet uses Spring configuration to discover the delegate components it needs for request mapping, view resolution, exception handling, and more.
internally it will register Spring mvc app and it will create an object and inject dependencies .
Is there a way to enable yaml configuration (instead of properties file) in normal spring web mvc application without using spring boot and have the #Value annotation supported.
I searched a lot, everywhere it uses spring boot. I am not intrested to use spring boot, as its very heavy and have many dependancies configured for auto setup.
Any help would be appreciated......
What's the best method to initiate a new Spring Project ?
Initiating Spring project is a lot of pain with various xml and db configuration.
Is there an "official" repository with complete sample project, as MVC with db access and so ?
Spring Boot may also be the solution, but some point still not clear to me :
How to add external components (such as Quartz) without creating some xml config ? (No such xml in Boot apparently)
Is a Spring Boot builded app is production-proof ?
As writen in the comments http://start.spring.io/ is the best way to start Spring boot project(STS has integration for it).
If you want to use something that is not supported by Spring Boot you can init spring beans the same way you do it in xml, just use java configuration. See this for example: http://www.tutorialspoint.com/spring/spring_java_based_configuration.htm
Also useing xml is still available. You can add #ImportResource on your Configuration class
#EnableAutoConfiguration
#Configuration
#ImportResource({"classpath*:applicationContext.xml"})
We have a fairly involved web application written using spring-mvc with a maven build system and would like to harness all the power of Grails for the front end.
So the Grails app will essentially call into the spring-mvc app's service layer to access its business logic and data.
I need some guidance with my architectural approach to this integration at a high level.
From my understanding, I will need to;
- add my spring-mvc app as a compile dependency in my BuildConfig.groovy.
- Expose the service layer objects as service beans in my conf/spring/resources.groovy and inject them into my controllers
Questions:
My spring-mvc app has lots of dependencies of its own (which it obviously has to have) which are causing lots of dependency errors. Should I be setting "transitive=false" in my config and calling all of these in my Grails app?
How should the datasource get configured? I guess I have to integrate the applicationContext of my spring-mvc app by calling it from my Grails applicationContext and hope it all bootstraps nicely?
So the Grails app will essentially call into the spring-mvc app's service layer to access its business logic and data
Can you be a bit more specific about which components of the Spring MVC you want to use from Grails, is it just the services and datasource?
I will need to add my spring-mvc app as a compile dependency in my BuildConfig.groovy
yes
Expose the service layer objects as service beans in my conf/spring/resources.groovy
Although you could make the Spring beans known to your Grails app by defining them individually in resources.groovy, this is unnecessary because you've already defined them in an Spring XML file (presumably) in the Spring MVC project.
Instead you can use the importBeans method of the BeanBuilder to import the Spring beans defined in this XML file into the Grails app. Once you've added the Spring MVC project as a dependency of your Grails app, the Spring XML file should be on your classpath, so all you need to do is add the following to resources.groovy
beans = {
importBeans('classpath:/path/to/file/applicationContext-services.xml')
}
How should the datasource get configured?
A Spring bean named dataSource defines the datasource that a Grails app uses. In a standard Grails app, this bean is created based on the configuration in DataSource.groovy. If your Spring MVC app defines a bean with this name, then this should be used instead after making the changes above. To be sure that Grails is using the datasource from your Spring MVC app rather than whatever is in DataSource.groovy, I guess you could delete the contents of the latter.