简体   繁体   English

如何在Spring中实例化Class / Bean并在构造函数中传递参数

[英]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.

相关问题 春天如何在不传递参数的情况下实例化@Autowired构造函数 - spring how to instantiate an @Autowired constructor without passing the parameter 将参数传递给Spring中构造函数中引用的Bean - Passing a parameter to a bean referenced in a constructor in Spring 我如何通过将对象作为参数传递来实例化CDI bean,就像我从参数化构造函数中以普通Java实例化新对象一样? - How do I instantiate a CDI bean by passing an object as parameter just like I instantiate a new object in plain Java from a parameterized constructor? Spring:如何实例化一个采用运行时参数的Spring bean? - Spring: how to instantiate a Spring bean that takes a runtime parameter? 使用InputStream构造函数参数实例化Spring bean - Instantiate Spring bean with InputStream constructor argument 如何实例化通用Spring bean? - How to instantiate generic spring bean? 如何使用带有Groovy闭包的构造函数参数实例化Java抽象类 - How to instantiate a Java abstract class with a constructor parameter with a groovy closure 如何在春季使用现有对象作为构造函数参数实例化Bean - How can I instantiate a bean in spring using an existing object as a constructor argument 使用接受字符串参数的构造函数实例化一个类对象? - Instantiate a class object with constructor that accepts a string parameter? 如何在Spring bean中传递类构造函数参数由注释自动装配 - How to pass class constructor parameters in Spring bean Autowired by annotations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM