when I was trying to add requestmapping annotation it got an error in the project .When I added
import org.springframework.web.bind.annotation.RequestMapping;
got an another error.
package com.example.demo.controller.user;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
#RequestMapping("Home")
public class HomeController {
}
Do you have the spring-web and spring-webmvc dependency mentioned in your pom.xml? If no then you have to add the same in pom.xml as dependencies.
You can refer the pom.xml from here: https://o7planning.org/en/10865/simple-crud-example-with-spring-mvc-restful-web-service
Related
I have generated a spring boot project from start.spring.io and imported it into STS. The tutorial I'm watching wants to run a JUNIT test before continuing. But when I try to run Junit test I get the following error "No tests found with test runner 'JUNIT 4'.
Also tested with following dependency
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
Any suggestion on how to fix this?
I suspect class DevopsApplicationTests. If I add class DevopsApplicationTests extends TestCase then unit test works but fails. Not sure what should be the correct code.
When testing "import org.junit.Test" I see the following errors.
When trying "import junit.framework.Test;" Also I get "No tests found with test runner 'JUNIT 4' like before but also there is a error near "#Test".
You're using the wrong import.
org.junit.jupiter.api.Test is the annotation for JUnit 5.
For JUnit 4, you need to import junit.framework.Test.
By the way, the latest version of STS is 3.8.0, released in 2017, based on Eclipse Neon from 2016.
STS is deprecated, and is replaced by 'Spring Tools 4 for Eclipse': https://spring.io/tools
Making the class Public fixed the issue.
package com.example.devops;
// import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
#SpringBootTest
public class DevopsApplicationTests {
#Test
public void contextLoads() {
}
}
What are analogs for classes from *autoconfigure.security.oauth2 and *security.oauth2 for Spring Boot 2.1.1.RELEASE version of spring-boot-starter-parent?
They are removed in this version.
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter;
import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter;
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
I think what you're missing is a dependency on spring-security-oauth2-autoconfigure to make your old setup work "seamlessly" with Spring Boot 2.1.1.RELEASE
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
That being said that project is maintenance mode and the recommended approach is to use the built in Spring Oauth support.
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
Learning hadoop programming from scratch.
I have written above line of code in eclipse.
it is showing error as "import org.apache.hadoop.io. cannot be resolved.".
I have already added external jar file "Hadoop-mapreduce-client-core-2.7.3,jar"
Is there anything else to add ?
In your all the dependents jar needs to be added, a single jar file wont help.
Try Using Maven.
Dependency is available on below link.
https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-core/1.2.1
1) Convert the project to a maven project if it's not yet.Project>Configure>Convert to maven project.
2)Add this dependency :
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.2.1</version>
</dependency>
This should resolve your errors. This worked for me!
I updated Spring Framework to 4.3.1, now I am getting an error:
The import cannot be resolved
for the following imports:
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
I have the following libraries for springframework 4.3.1;
spring-core-4.3.1.RELEASE.jar,
aop, aspects, beans, context, context-support,expression, instrument,
instrument-tomcat, jdbc, jms, messaging, orm, tx, websocket
I am not using Maven. Others: Java 8, Liferay 4.3.1, Hibernate 5.2. How can I fix it?
The mail library is found in spring-context-support so download spring-context-support-4.3.1.RELEASE.jar and add that in your classpath
Without maven you may know that you must place the jar in classpath. Follow the jar.
Java Mail Jar
Check those steps on link above and you'll get it.
Spring Mail Integration
If work, tell us a feedback.
Regards
If it was Maven you could add the following to your dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
I have a spring boot application
The structure of my application is:
src
main
java
org
Application.java
service
--another classes are here
Application.java
package org.baharan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class Application {
public static void main(String[] args) throws Throwable {
SpringApplication.run(Application.class, args);
}
}
Another confirguration class files sush as oracle config and security config are in another application(is named core) is added in my pom.xml
<dependency>
<groupId>org.baharan.amad</groupId>
<artifactId>core</artifactId>
<version>1.0-releases</version>
<type>war</type>
</dependency>
When i build my application, all of classes and properties files of core application are added in my target by overlay maven
When i excute Application.java,spring boot couldn't find any config class isn't in my application but they are in core(after build all of them is added in my target)
In other word how spring boot load configuration classes which dont exist in current application.
please help me.
If they're spring configs you can still use #ComponentScan to load in other bean configs e.g.
#ComponentScan("classpath*:com.myorg.conf")
and
#ComponentScan("classpath*:conf/appCtx.xml")