[英]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);
}
}
Passing arguments when autowiring interfaces it's only possible in XML config. 自动装配接口时传递参数,只有在XML配置中才可以。 Simmilar question is here: Spring autowire interface Simmilar问题在这里: Spring Autowire 接口
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.