1.resources下(src/main/resources)
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("authfile.txt"); Properties properties = new Properties(); properties.load(in);
2
Properties props = PropertiesLoaderUtils.loadAllProperties("authfile.txt");
3
File files = ResourceUtils.getFile("classpath:authfile.txt");
4
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name="location" value="(propertis文件名)Xxx.properties" /> </bean> 三、访问properties中的内容: <bean id="Xxx" ....> <property name="Xxx" value=" ${键} " /> //${键},键properties文件中的键值对的键 </bean>
5
@Component @PropertySource("classpath:db.properties") public class DBConnection { @Value("${DB_DRIVER_CLASS}") private String driverClass; @Value("${DB_URL}") private String dbUrl; @Value("${DB_USERNAME}") private String userName; @Value("${DB_PASSWORD}") private String password;