1

I have below class Structure:

public class MyClass {}
public class AnotherClass {}
public class YetAnotherClass {}

@Component
public class MyFieldSetMapper extends BeanWrapperFieldSetMapper<MyClass>{
    public MyFieldSetMapper() {
        setTargetType(MyClass.class);
    }
}

and I need to autowire the class in another class, The problem here is that I have to autowire a lot of MyFieldSetMapper types, i.e.

@Component
public class AnotherFieldSetMapper extends BeanWrapperFieldSetMapper<AnotherClass>{
    public AnotherFieldSetMapper() {
        setTargetType(AnotherClass.class);
    }
}

and for yet another FieldSetMapperClass I have to dot this:

@Component
public class YetAnotherFieldSetMapper extends BeanWrapperFieldSetMapper<YetAnotherClass>{
    public AnotherFieldSetMapper1() {
        setTargetType(YetAnotherClass.class);
    }
}

and I am duplicating a lot of code writing a new field set mapper every time I have a need of new mapper and I hate It. Could anyone please suggest me a much smarter/better code?

Naresh Kumar
  • 673
  • 7
  • 17

1 Answers1

-5

I dont get what you mean with "autowire". But since you say you want to write generic classes - do it:

public class MyClass<T, U>{
    T foo;
    U bar;
}

Well, I think I dont get your problem and this answer wont help a lot.

Daddelbob
  • 406
  • 4
  • 13
  • He is asking about the mechanism of DI, and "autowiring" is the means that spring uses to do DI, similar to @inject. More info here: http://stackoverflow.com/questions/4997836/benefit-of-autowired-annotation-in-java – Fausto Carvalho Marques Silva Jul 27 '16 at 18:01
  • 2
    *Well, I think I dont get your problem and this answer wont help a lot.* Pretty accurate assessment, lol. – shmosel Jul 27 '16 at 18:39