Skip to content

Using without Spring Boot #250

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

Closed
prowave opened this issue Dec 11, 2019 · 9 comments
Closed

Using without Spring Boot #250

prowave opened this issue Dec 11, 2019 · 9 comments

Comments

@prowave
Copy link

prowave commented Dec 11, 2019

I have a project that I cannot convert to a Spring Boot project due to older dependencies. Can you provide a guide to use this project without Spring Boot? Is it possible?

Thank you for providing this.

@springdoc
Copy link
Collaborator

Hi @prowave,

You just need to scan for the following springdoc class: org.springdoc.config.SpringDocConfiguration

For example, you can simply add on your application that ships the springdoc-openapi dependency: @ComponentScan(basePackages = {"org.springdoc"})

@nmasilva
Copy link

Hi @prowave,

You just need to scan for the following springdoc class: org.springdoc.config.SpringDocConfiguration

For example, you can simply add on your application that ships the springdoc-openapi dependency: @ComponentScan(basePackages = {"org.springdoc"})

Hi,
Didn't work for me.
The webapp starts with no errors, but with nothing deployed.
In version 1.3.0 the path org.springdoc.config.SpringDocConfiguration is not available, shoud it be: "org.springdoc.core.SpringDocConfiguration" ? anyhow tried with both.

Thank's
Nuno

@bnasslahsen
Copy link
Collaborator

Hi @nmasilva,

Please have a look at the answer on stackoverflow:

If you have a sample project to reproduce your issue, you can add the link for it on github and will have a look at it.

@nmasilva
Copy link

Hi @bnasslahsen

Thank you for your reply.
I already tried the solution on the link you posted.
Below is a project sandbox with the configuration that you posted above and is not working:
https://bitbucket.org/nmasilva/openapispringmvc

  1. mvn clean package
  2. docker-compose up
  3. http://{docker_localhost_address}:8080/greeting/ (404 error)

If you removed the springboot and openapi dependencies in the war project pom, as de @import in the AppInitializer.java, it will work and you'll get as response 202 with the message: "Hello World!"

Thank you,
Nuno

@bnasslahsen
Copy link
Collaborator

@nmasilva,

You can find attached, a sample working configuration for spring apps (without spring-boot).
openapispringmvc.zip

@nmasilva
Copy link

Hi @bnasslahsen

Thank you for the sample. Works like a charm :)
I've made some simplifications and push it into the sample project branch mentioned above.

Thank again,
Nuno

@bnasslahsen
Copy link
Collaborator

Great !
Will update the F.A.Q and stackoverflow as well.

@BhargavRuparel3591
Copy link

We have Spring framework (version 5.3.22) based application, not a spring boot.

We have added springdoc-openapi (1.6.11) dependency along with below openapi configuration.

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = {"org.springdoc","rest"}) 
@Import({org.springdoc.core.SpringDocConfiguration.class, 
         org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class, 
         org.springdoc.webmvc.ui.SwaggerConfig.class, 
         org.springdoc.core.SwaggerUiConfigProperties.class, 
         org.springdoc.core.SwaggerUiOAuthProperties.class, 
         org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class}) 
public class OpenApiConfig implements WebMvcConfigurer { }

In our application, we have multiple projects having mixed of Java configurations and XML based configurations.

Both types of classes (java config like @controller/@service and XML definitions like <bean id="".... >) are having dependencies injected through @Autowred.

The classes having beans created through component scanning (@controller/@service) are working well, all the injected dependecies are resolved as expected.
But the classes having XML definitions are having issues, where dependencies injected through setter and bean ref are working fine, but the dependencies injected through @Autowired are found as null at runtime. Looks like @Autowired annotation itself is not getting resolved while creating bean of such classes. We have also verified that our XML context file has <context:annotation-config /> defined and so @Autowired should get resolved here.

Without this springdoc-openpi dependency and these OpenApiConfig, we are not facing this issue.

Does anyone have more insights here ?

@nonault
Copy link

nonault commented Jul 18, 2023

We have Spring framework (version 5.3.22) based application, not a spring boot.

We have added springdoc-openapi (1.6.11) dependency along with below openapi configuration.

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = {"org.springdoc","rest"}) 
@Import({org.springdoc.core.SpringDocConfiguration.class, 
         org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class, 
         org.springdoc.webmvc.ui.SwaggerConfig.class, 
         org.springdoc.core.SwaggerUiConfigProperties.class, 
         org.springdoc.core.SwaggerUiOAuthProperties.class, 
         org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class}) 
public class OpenApiConfig implements WebMvcConfigurer { }

In our application, we have multiple projects having mixed of Java configurations and XML based configurations.

Both types of classes (java config like @controller/@service and XML definitions like <bean id="".... >) are having dependencies injected through @Autowred.

The classes having beans created through component scanning (@controller/@service) are working well, all the injected dependecies are resolved as expected. But the classes having XML definitions are having issues, where dependencies injected through setter and bean ref are working fine, but the dependencies injected through @Autowired are found as null at runtime. Looks like @Autowired annotation itself is not getting resolved while creating bean of such classes. We have also verified that our XML context file has <context:annotation-config /> defined and so @Autowired should get resolved here.

Without this springdoc-openpi dependency and these OpenApiConfig, we are not facing this issue.

Does anyone have more insights here ?

Hi, did u solve ur problem ? I have the same one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants