How to get rid of this error{<Component-import> cannot be used when atlassian plugin key is set}?

That tutorial is using the old <component-import and <component on things. Your project is more than likely using a project generated from the sdk which would be using spring-scanner. With Spring Scanner you’d annotate each class with @Component that you want use as a component and any imports - you’d do @ComponentImport in the class.

Now the bad news - PluginScheduler is deprecated. The replacement is the atlassian-scheduler. Take a look at How to use the Atlassian Scheduler