企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
``` 1. 加载properties配置文件 2. 编写在类上面 3. 相当于context:property-placeholder标签 ``` ### 属性 ``` value[]:用于指定properties文件路径,如果在类路径下,需要写上classpath ``` ``` @Configuration @PropertySource(“classpath:jdbc.properties”) public class JdbcConfig { @Value("${jdbc.driver}") private String driver; @Value("${jdbc.url}") private String url; @Value("${jdbc.username}") private String username; @Value("${jdbc.password}") private String password;   /** * 创建一个数据源,并存入 spring 容器中 * @return */ @Bean(name="dataSource") public DataSource createDataSource() { try { ComboPooledDataSource ds = new ComboPooledDataSource(); ds.setDriverClass(driver); ds.setJdbcUrl(url); ds.setUser(username); ds.setPassword(password); return ds; } catch (Exception e) { throw new RuntimeException(e); } } } ```