I'm new to Spring.
Back in the not so long ago days.
I have a Helper Class with static methods help to assemble and build objects.
But i realize I can't @Autowired static variables.
May I know what is spring replacement for helper class with static method? Or I should make them into @Service classes too?
You can use @Component annotated classes. It is the base of all other components. Your class would be something like :
import org.springframework.stereotype.Component;
@Component("assembler") // giving name to component is not mandatory, could be @Component
public class Assembler {
public boolean assemble(Object obj) {
// your stuff here
}
}
This is your assembler component. You can use this in other classes using :
@Controller
public class MyController {
@Autowired
private Assembler assembler;
@RequestMappings(//mappings done here)
public String showMsg() {
// here you use assembler component
boolean response = assembler.assemble(new Object());
System.out.println(response);
}
}
This is just an example. I hope you get my point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With