I am using latest version of IntelliJIDEA CE edition (11.0.4). There is one thing that I could not find anywhere, and it is a blocker for my further improvements with Java/Spring.
Controller:
import com.example.demo.classes.SaveToFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MainController {
@Autowired protected SaveToFile saveToFile;
//@Autowired SaveToDb saveToDb;
@RequestMapping("/start")
public String whatever(@RequestParam(value="name", defaultValue="World") String name) {
saveToFile.save(name);
return "something";
//return new SaveToFile(name);
}
}
Class: import com.example.demo.interfaces.ISave;
public class SaveToFile implements ISave {
private String filename = "Vlad";
@Override
public void save(String name) {
System.out.println("Saving " + name + " to file.");
}
public String getFilename(){
return filename;
}
}
Class Interface:
public interface ISave {
void save(String name);
}
Nothing fancy, just to get a grasp of Spring and Java.
Inside my Controller, when I try to use
@Autowired protected SaveToFile saveToFile;
I get an error that prevents app from starting. Here is the error:
Execution failed for task ':DemoApplication.main()'.
Process 'command '/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
If I comment that out, I can instantiate my class with "new", but thats not the point.
I have tried changing SDK's in the Project Structure menu option. but to no avail. Maybe worth to point out, that similar project I also work on in Kotlin, has no issues at all. I tried to Mimick the "Kotlin" settings, but nothing.
Does anyone have any clue as to what is going on in here?