1
我有一个Maven控制器春天的web应用程序,它运行良好与mvn clean tomcat:run
命令行,但我不能让它与运行/调试配置。我收到一长串自动故障依赖性故障,结束于:春天:mvn干净的tomcat:运行在命令行上但不是IntelliJ
... bean的实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法 实例化bean类 [com.mycompany.config.DataSourceConfig $$ EnhancerByCGLIB $$ 543b87de]: 构造函数抛出异常;嵌套的例外是 java.lang.NumberFormatException:空
这里是有问题的类:
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import java.net.URISyntaxException;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;
@Configuration
public class DataSourceConfig {
//change PACKAGE_TO_SCAN
private static final String PACKAGE_TO_SCAN = "com.mycompany";
private static final int MODE_DEV = 0;
private static final int MODE_STG = 1;
private static final int MODE_PROD = 2;
private Logger log = LoggerFactory.getLogger(this.getClass());
private int environment = Integer.parseInt(System.getenv("ENVIRONMENT"));
private String dburl = System.getenv("UMWORKFLOW_DATABASE_URL");
private String dbuser = System.getenv("UMWORKFLOW_DATABASE_USER");
private String dbpass = System.getenv("UMWORKFLOW_DATABASE_PASSWORD");
public DataSourceConfig(){
}
@Bean(destroyMethod="close")
public ComboPooledDataSource dataSource() throws URISyntaxException, PropertyVetoException {
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass("org.postgresql.Driver");
ds.setMinPoolSize(1);
ds.setMaxPoolSize(10);
ds.setAcquireIncrement(1);
ds.setIdleConnectionTestPeriod(300);
ds.setMaxStatements(0);
ds.setCheckoutTimeout(100);
ds.setJdbcUrl(dburl);
ds.setUser(dbuser);
ds.setPassword(dbpass);
return ds;
}
@Bean
public AnnotationSessionFactoryBean sessionFactory() throws URISyntaxException, PropertyVetoException {
AnnotationSessionFactoryBean sf = new AnnotationSessionFactoryBean();
sf.setDataSource(dataSource());
String[] packageToScan = new String[1];
packageToScan[0] = PACKAGE_TO_SCAN;
sf.setPackagesToScan(packageToScan);
Properties hibProp = new Properties();
hibProp.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
//modes create, create-drop, update, validate
if(environment == MODE_DEV) {
hibProp.put("hibernate.hbm2ddl.auto", "update");
} else if (environment == MODE_STG) {
hibProp.put("hibernate.hbm2ddl.auto", "update");
} else {
hibProp.put("hibernate.hbm2ddl.auto", "update");
}
sf.setHibernateProperties(hibProp);
return sf;
}
}