user1551766
user1551766

Reputation: 11

How to instantiate a Class/Bean in Spring passing parameter in constructor

I need to Autowire service interface in my controller, passing parameter logcode in not default service constructor

 @Controller
    public class FooController {

        private Foo foo;

        @Autowired
        private FooService fooService //(I like passe parameter here);

    }

Here's my Service:

I need to Autowire service interface in my controller, passing parameter logcode in not default service constructor

 @Service
    public class FooServiceImpl implements FooService {

        @Autowired
        private FooDAO fooDAO;

    public FooServiceImpl(String pLogCode)
    {

    }

        @Transactional
        public void addFoo(Foo foo) {
            fooDAO.addFoo(foo);
        }


    }

Upvotes: 0

Views: 2196

Answers (1)

k0staa
k0staa

Reputation: 342

Passing arguments when autowiring interfaces it's only possible in XML config. Simmilar question is here: Spring autowire interface

Upvotes: 1

Related Questions