I' m writing a project currently using spring' s javaconfig without spring xml files. And now I' m facing a problem.
I have a properties config file and I want to make it a spring's @Component
, but I can't find a nice way to inject the properties to the bean's field just like in the @Configuration
with @PropertySource
. It uses @Value
or @Inject
Environment to get the properties.
and now my bean is not @Configuration and I don't want to make it with @Bean
in the @Configuration
class. I want it auto-scaned by spring.
does somebody has some ideas?
In the Java configuration
@Configuration
@PropertySource(name = "props", value = { "classpath:myProps.properties" })
public class AppConfig {
In some Spring bean
@Autowired
@Qualifier("props")
private Properties myProperties;//+setter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.