2014-12-22 4 views
0

Я разрабатываю проект с спящим и весенним. Я использую аннотации для всех. Я пытаюсь развернуть в OpenShift в JBOSS AS 7. Все время я получаю ошибки с компонентом DataSource, и я не знаю, что я делаю неправильно.DataSource имеет значение null - Развертывание на OpenShift JBOSS AS 7

В журнале появится:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [clanwar/config/MainConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource clanwar.config.MainConfig.dataSource()] threw exception; nested exception is java.lang.NullPointerException 

Вы можете проверить полный трассировки стека здесь: http://clanwaropenshift-stel.rhcloud.com/

Мой DataSource боб:

@Bean 
public DataSource dataSource() { 
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); 
    Driver driver = null; 
    try { 
     driver = new com.mysql.jdbc.Driver(); 
    } catch (SQLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    dataSource.setDriver(driver); 
    dataSource.setUrl(env.getProperty(JDBC_URL)); 
    dataSource.setUsername(env.getProperty(JDBC_USER)); 
    dataSource.setPassword(env.getProperty(JDBC_PASSWORD)); 
    return dataSource; 
} 

Также я стараюсь с DriverManagerDataSource и org.apache.commons.dbcp.BasicDataSource, но все я получаю ту же ошибку.

Заранее спасибо.

1 EDIT

Когда приложение развертывает, регистратор показывает создать два раза DataSource. Первое шоу: окр ->StandardServletEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment,class path resource [application.properties]]} DataSource ->[email protected]

Но второй раз показывает: окр ->null DataSource ->[email protected]

Часть журнала:

014/12/22 11:39:42,848 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-3) Refreshing Root WebApplicationContext: startup date [Mon Dec 22 11:39:42 EST 2014]; root of context hierarchy 
2014/12/22 11:39:43,035 INFO [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (MSC service thread 1-3) Registering annotated classes: [class clanwar.config.MainConfig,class clanwar.config.MvcConfig,class clanwar.config.SecurityConfig] 
2014/12/22 11:39:43,673 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Overriding bean definition for bean 'propertyPlaceHolderConfigurer': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=mainConfig; factoryMethodName=propertyPlaceHolderConfigurer; initMethodName=null; destroyMethodName=(inferred); defined in class clanwar.config.MainConfig] with [Root bean: class [clanwar.config.MvcConfig]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=propertyPlaceHolderConfigurer; initMethodName=null; destroyMethodName=(inferred); defined in class clanwar.config.MvcConfig] 
2014/12/22 11:39:44,443 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-3) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2014/12/22 11:39:45,385 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:45,394 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:45,394 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:45,400 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) StandardServletEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment,class path resource [application.properties]]} 
2014/12/22 11:39:45,401 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) [email protected] 
2014/12/22 11:39:45,407 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:45,407 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:45,409 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:45,641 INFO [org.hibernate.annotations.common.Version] (MSC service thread 1-3) HCANN000001: Hibernate Commons Annotations {4.0.1.Final} 
2014/12/22 11:39:45,648 INFO [org.hibernate.Version] (MSC service thread 1-3) HHH000412: Hibernate Core {4.2.0.Final} 
2014/12/22 11:39:45,652 INFO [org.hibernate.cfg.Environment] (MSC service thread 1-3) HHH000206: hibernate.properties not found 
2014/12/22 11:39:45,655 INFO [org.hibernate.cfg.Environment] (MSC service thread 1-3) HHH000021: Bytecode provider name : javassist 
2014/12/22 11:39:46,467 WARN [org.hibernate.mapping.RootClass] (MSC service thread 1-3) HHH000038: Composite-id class does not override equals(): clanwar.model.ClanMember 
2014/12/22 11:39:46,467 WARN [org.hibernate.mapping.RootClass] (MSC service thread 1-3) HHH000039: Composite-id class does not override hashCode(): clanwar.model.ClanMember 
2014/12/22 11:39:46,469 WARN [org.hibernate.mapping.RootClass] (MSC service thread 1-3) HHH000038: Composite-id class does not override equals(): clanwar.model.WarPlayer 
2014/12/22 11:39:46,469 WARN [org.hibernate.mapping.RootClass] (MSC service thread 1-3) HHH000039: Composite-id class does not override hashCode(): clanwar.model.WarPlayer 
2014/12/22 11:39:46,621 WARN [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] (MSC service thread 1-3) HHH000342: Could not obtain connection to query metadata : Cannot load connection class because of underlying exception: 'java.lang.NumberFormatException: For input string: "$OPENSHIFT_MYSQL_DB_PORT"'. 
2014/12/22 11:39:46,630 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-3) HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect 
2014/12/22 11:39:46,666 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-3) HHH000422: Disabling contextual LOB creation as connection was null 
2014/12/22 11:39:46,735 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-3) HHH000399: Using default transaction strategy (direct JDBC transactions) 
2014/12/22 11:39:46,758 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-3) HHH000397: Using ASTQueryTranslatorFactory 
2014/12/22 11:39:46,950 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-3) Hibernate Validator 4.2.0.Final 
2014/12/22 11:39:48,873 INFO [org.springframework.orm.hibernate4.HibernateTransactionManager] (MSC service thread 1-3) Using DataSource [[email protected]d6] of Hibernate SessionFactory for HibernateTransactionManager 
2014/12/22 11:39:49,639 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (MSC service thread 1-3) Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Mon Dec 22 11:39:42 EST 2014]; root of context hierarchy 
2014/12/22 11:39:49,861 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/war/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.WarController.warHandler() 
2014/12/22 11:39:49,866 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/war/create],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.WarController.createWarHandler() 
2014/12/22 11:39:49,877 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/war/new],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.WarController.newWarHandler(java.util.List<java.lang.String>) 
2014/12/22 11:39:49,878 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/war/search],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.WarController.searchWarHandler(int) 
2014/12/22 11:39:49,879 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/war/saveplayer],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.WarController.savePlayerInWarHandler(clanwar.model.WarPlayer) 
2014/12/22 11:39:49,888 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/createPinpinelas],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void clanwar.controller.HelperController.playerSaveHandler() 
2014/12/22 11:39:49,893 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/json/test],methods=[],params=[],headers=[],consumes=[],produces=[application/json],custom=[]}" onto public clanwar.model.WarPlayer clanwar.controller.HelperController.jsonTest() 
2014/12/22 11:39:49,893 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.HelperController.mvcTest() 
2014/12/22 11:39:49,901 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/login],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.LoginController.playerLoginHandler(java.lang.String) 
2014/12/22 11:39:49,914 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/signup],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.LoginController.signUpViewHandler() 
2014/12/22 11:39:49,920 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/signup],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.LoginController.signUpHandler(clanwar.model.Player) 
2014/12/22 11:39:49,922 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/choose],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanChooseHandler() 
2014/12/22 11:39:49,932 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/new],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanNewViewHandler() 
2014/12/22 11:39:49,933 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/new],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanNewHandler(clanwar.model.Clan,java.lang.String) 
2014/12/22 11:39:49,933 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/select],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanSelectHandler() 
2014/12/22 11:39:49,934 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/view],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanViewHandler() 
2014/12/22 11:39:49,934 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/join],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanJoinHandler(clanwar.model.ClanMember) 
2014/12/22 11:39:49,935 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/clan/leave],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.ClanController.clanLeaveHandler(clanwar.model.ClanMember) 
2014/12/22 11:39:49,939 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.MainController.homeHandler(java.security.Principal) 
2014/12/22 11:39:49,940 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/denied],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.MainController.deniedHandler() 
2014/12/22 11:39:49,941 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/json/war],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public clanwar.model.War clanwar.controller.JsonController.jsonWarHandler(int) 
2014/12/22 11:39:49,941 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/json/wars],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<clanwar.model.War> clanwar.controller.JsonController.jsonWarsHandler() 
2014/12/22 11:39:49,943 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/player/update],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void clanwar.controller.PlayerController.playerUdapteHandler(clanwar.model.Player) 
2014/12/22 11:39:49,950 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/player/profile],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.PlayerController.profileHandler() 
2014/12/22 11:39:49,950 INFO [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (MSC service thread 1-3) Mapped "{[/player/password],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView clanwar.controller.PlayerController.passwordHandler() 
2014/12/22 11:39:49,998 INFO [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping] (MSC service thread 1-3) Mapped URL path [/web/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 
2014/12/22 11:39:51,306 INFO [org.springframework.security.web.DefaultSecurityFilterChain] (MSC service thread 1-3) Creating filter chain: Ant [pattern='/web/**'], [] 
2014/12/22 11:39:51,447 INFO [org.springframework.security.web.DefaultSecurityFilterChain] (MSC service thread 1-3) Creating filter chain: [email protected]1, [org.springframework.secu[email protected]1c1d169, org.spring[email protected]128953, [email protected]e, [email protected], org.[email protected]c1924a, org.springframework.s[email protected]ac9750, org.sp[email protected]29470e, org.springframework.[email protected]baae53, org.springframework.securi[email protected]37eaff, org.springfram[email protected]19b7bc4, o[email protected]f6d8e6, org[email protected]137a0cf, org.springfr[email protected]629d2e] 
2014/12/22 11:39:51,573 INFO [org.springframework.web.context.ContextLoader] (MSC service thread 1-3) Root WebApplicationContext: initialization completed in 8731 ms 
2014/12/22 11:39:51,636 INFO [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] (MSC service thread 1-3) Initializing Spring FrameworkServlet 'spring/spring-context' 
2014/12/22 11:39:51,649 INFO [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-3) FrameworkServlet 'spring/spring-context': initialization started 
2014/12/22 11:39:51,688 INFO [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-3) Refreshing WebApplicationContext for namespace 'spring/spring-context-servlet': startup date [Mon Dec 22 11:39:51 EST 2014]; parent: Root WebApplicationContext 
2014/12/22 11:39:51,742 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] (MSC service thread 1-3) Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/spring-context-servlet.xml] 
2014/12/22 11:39:52,976 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Overriding bean definition for bean 'propertyPlaceHolderConfigurer': replacing [Root bean: class [clanwar.config.MvcConfig]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=propertyPlaceHolderConfigurer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [clanwar/config/MvcConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=mainConfig; factoryMethodName=propertyPlaceHolderConfigurer; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [clanwar/config/MainConfig.class]] 
2014/12/22 11:39:53,116 WARN [org.springframework.context.annotation.ConfigurationClassEnhancer] (MSC service thread 1-3) @Bean method MainConfig.propertyPlaceHolderConfigurer is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details 
2014/12/22 11:39:53,193 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-3) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2014/12/22 11:39:53,489 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:53,495 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:53,497 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:53,497 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) null 
2014/12/22 11:39:53,497 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) [email protected] 
2014/12/22 11:39:53,497 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:53,497 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
2014/12/22 11:39:53,498 INFO [clanwar.config.MainConfig] (MSC service thread 1-3) ___________________________________________________________ 
+0

К сожалению, основная причина проглатывается. Я уверен, что openshift имеет некоторую поддержку для ведения журнала приложений, поэтому журнал, если «драйвер» или «env» имеет значение NULL, по крайней мере, может сузить то, что точно равно нулю в вашем коде. – Gimby

+0

@Gimby я редактировал мой вопрос. – Arturo

+0

К сожалению, это не пришло вам в голову, когда вы поняли, что env на самом деле имеет значение null, чтобы фактически добавить код, показывающий, откуда приходит env. – Gimby

ответ

0

Моя проблема связана с web.xml и spring-mvc-dispatcher.xml, у меня есть <component-scan ...>, которые создают конфигурацию два раза (я не знаю почему). Удаление этикетки <component-scan ...> Я решаю все.