I have a spring boot project that is structured like below:
client
build.gradle
interface
build.gradle
service
tests
main
java
resources
build.gradle
So there are three subprojects: interface,service and client.
The controllers are inside service>main>controller and the swagger is configured inside the build.gradle which is inside the service project.
When i do localhost:8080/swagger-ui.html ,i get:
No mapping found for HTTP request with URI [/swagger-ui.html] in DispatcherServlet with name 'dispatcherServlet'.
I am able to get json when i hit this url:
http://localhost:8080/v2/api-docs
I got this working,
I had a #EnableWebMVC on top of a class.Removing it fixed it.
Thanks #Sampada for your help
first, add below dependencies in spring boot pom file, then add #EnableSwagger annotation on the application class and then add webappconfig class
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.1</version>
</dependency>
#Configuration
#EnableWebMvc
public class ApplicationWebMvcConfig implements WebMvcConfigurer {
#Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer
configurer) {
configurer.enable();
}
}
Related
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Getmapping;
#Controller
public class HomeController {
#GetMapping("/")
public String home(){
return "hone";
}
}
I just can't import org.springframework.web so that I can't use #GetMapping.
How to solve this problem?
Should I add more dependencies?
Add spring-web module to your classpath.
Gradle
compile group: 'org.springframework', name: 'spring-web', version: '5.2.6.RELEASE'
Maven
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.6.RELEASE</version>
</dependency>
In build.gradle, under dependencies, add:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
// TODO: Add this implementation
implementation 'org.springframework:spring-web:5.3.15'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Then, as shown below, be sure to 'Reload All Gradle Projects'.
For additional context, consult the docs on Maven Repository.
Essentially, we have to specify this source for our import to know from where to import.
It's not clear to me why this isn't part of the offerings whenever we use the Spring Intializr. 🤷🏾♂️
I am new to swagger, and trying to integrate swagger2 with my Spring MVC (4.3.10 release) application which will be deployed into WAS 8.5.5. At the time of application startup, I am getting the below error,
Caused by: java.lang.VerifyError: JVMVRFY013 class loading constraint violated; class=org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint, method=getSourceLocation()Lorg/aspectj/lang/reflect/SourceLocation;, pc=0
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:85)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:162)
at org.springframework.aop.aspectj.AspectJAroundAdvice.lazyGetProceedingJoinPoint(AspectJAroundAdvice.java:81)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
My swagger configurations are as below,
Added swagger dependencies in pom.xml
<!-- Swagger dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>
Added below annotations to my controller classes/operations
#Api(value="someController", description="services API")
#ApiOperation(value = "someOperation")`
Swagger reource configuration in applicationContext.xml
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<mvc:resources mapping="/swagger-ui.html" location="classpath:/META-INF/resources/swagger-ui.html"/>
<mvc:default-servlet-handler/>
<bean id="swagger2Config" class="springfox.documentation.swagger2.configuration.Swagger2DocumentationConfiguration"/>
SwaggerConfig class
#Configuration
#EnableSwagger2
public class SwaggerConfig {
#Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("TITLE")
.description("Description")
.version("1.0")
.build();
}
}
Any help on this would be greatly appreciated. Thanks
I am trying to test google cloud storage in local mvn jetty server.
defining the following java servlet I get the following error during servlet initiallization.
#WebServlet(name = "receiveImage", value = "receiveImage")
#SuppressWarnings("serial")
#MultipartConfig()
public class receiveImage extends HttpServlet {
private static final String BUCKET_NAME = "testbucket";
private static Storage storage = null;
#Override
public void init() {
storage = StorageOptions.defaultInstance().service();
}
HTTP ERROR 500
Problem accessing /receiveImage. Reason:
Server Error
Caused by:
java.lang.IllegalAccessError: tried to access method com.google.cloud.ServiceOptions.getFromServiceLoader(Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object; from class com.google.cloud.HttpServiceOptions
at com.google.cloud.HttpServiceOptions.(HttpServiceOptions.java:154)
at com.google.cloud.storage.StorageOptions.(StorageOptions.java:69)
at com.google.cloud.storage.StorageOptions.(StorageOptions.java:27)
at com.google.cloud.sto
i define the following maven dependency in pom file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>0.4.0</version>
</dependency>
Appreciate for helps.
I could resolve the issue:
there is a conflict between these two dependencies:
dependency>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-datastore</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>0.5.1</version>
</dependency>
I just changed the first dependency to
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
<version>0.5.1</version>
</dependency>
I wanted to implement Jawr for minification and obfuscation of CSS and JS resources. I am using a Spring MVC project where the configurations are done using Java code using annotations and XML is not used. Now able to find a documentation for the same. Can some one suggest me the configuration or a reference link.
jawr dependencies to your pom:
<dependency>
<groupId>net.jawr</groupId>
<artifactId>jawr-core</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>net.jawr.extensions</groupId>
<artifactId>jawr-spring-extension</artifactId>
<version>3.6</version>
</dependency>
Build a controller like this:
#Controller
public class JsController extends JawrSpringController
{
public JsController ()
{
setType("js");
setConfigLocation("/jawr.properties");
}
#RequestMapping("/js/**")
public void javascript ( HttpServletRequest request, HttpServletResponse response ) throws Exception
{
handleRequest(request, response);
}
}
#Bean
public JavaMailSender mailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setDefaultEncoding("UTF-8");
mailSender.setHost("smtp.googlemail.com");
mailSender.setPort(465);
mailSender.setUsername("XXXXXXXXX#gmail.com");
mailSender.setPassword("XXXXXXXXXXXXXXX");
Properties properties = new Properties();
properties.put("mail.smtp.auth", true);
properties.put("mail.smtp.starttls.enable", true);
mailSender.setJavaMailProperties(properties);
return mailSender;
}
I am trying to send mail using javamailsender for that i configured the above code using annotations after that I get the "java.lang.NoClassDefFoundError: org/springframework/core/type/AnnotatedTypeMetadata" exception any suggestions appriciate.
It seems dependency spring-core is missing. You should add this jar.
Or using maven choose a dependency from here: http://mvnrepository.com/artifact/org.springframework/spring-core
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.6.RELEASE</version>
</dependency>