c3p0config.properties.
jdbcUrl = "jdbc:mysql://localhost:3306/myproject1_simplesite"
driverClass = "com.mysql.jdbc.Driver"
user = "root"
password = "root"
use javaconfig to configure Dao explicitly
@Configuration
public class DaoConfig {
@Bean(name = "dataSource")
public DataSource c3p0DataSource(){
ComboPooledDataSource c3p0dataSource = new ComboPooledDataSource();
c3p0dataSource.setJdbcUrl(-sharp{ c3p0config.properties jdbcurl});
}
@Bean(name = "userDao")
public UserDao userDao(){
}
}
I know that SpEL allows-sharp {beanid.attr}
but now I only want to use properties files, but can I use SpEL to explicitly express the attribute values in properties without creating a bean? (the so-called explicit expression, such as I also have a connection pool properties file, also has these four attributes. After I load both properties (of course, first of all, I have to solve the problem of how to load), how do I name the collection of key-value pairs loaded by the two properties respectively? )
Thank you
I read Spring"s actual combat book, and to be honest, I don"t think it"s friendly. Explain several different operations that achieve the same goal, but although some settings are common and necessary in different operations, they will only be mentioned in the first operation and will not be mentioned later. In
Spring, an example is given:
\-sharp {SystemProperties ["disc.title"]}
but I can"t find out where SystemProperties is defined in the context.
and then read back. I found that
@ PropertySource (. Was used in "declaring attribute sources and retrieving attributes through Spring"s Environment". App.properties)
then there is disc.title, in app.properties, which is a setting in context that has something to do with \-sharp {SystemProperties ["disc.title"]}
.
I can only reason from this:
in displaying javaconfig configuration, you can load all key-value pairs in a properties into SystemProperties
by @ PropertySource (.)
. Then SystemProperties ["AttributeName"]
can get the attribute value corresponding to attributename. If there are two properties files that contain the same property name, the solution is to prefix the property name in the properties file. For example, jdbcUrl should be named c3p0.jdbcUrl in the configuration file to avoid the problem of duplicate names.