2017-03-08 133 views
0

我在我的stanalone應用程序中使用Springboot + Spring JPA。但我geeting以下錯誤:工廠方法'stringHttpMessageConverter'拋出異常;嵌套異常是java.lang.NullPointerException

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.http.converter.StringHttpMessageConverter]: Factory method 'stringHttpMessageConverter' threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ... 69 more Caused by: java.lang.NullPointerException at java.nio.charset.Charset.put(Unknown Source) at java.nio.charset.Charset.access$200(Unknown Source) at java.nio.charset.Charset$3.run(Unknown Source) at java.nio.charset.Charset$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.nio.charset.Charset.availableCharsets(Unknown Source) at org.springframework.http.converter.StringHttpMessageConverter.(StringHttpMessageConverter.java:67) at org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration.stringHttpMessageConverter(HttpMessageConvertersAutoConfiguration.java:77) at org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration$$EnhancerBySpringCGLIB$$4ce1453d.CGLIB$stringHttpMessageConverter$0() at org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration$$EnhancerBySpringCGLIB$$4ce1453d$$FastClassBySpringCGLIB$$1235f10b.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) at org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration$$EnhancerBySpringCGLIB$$4ce1453d.stringHttpMessageConverter() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ... 70 more

我的配置類,如下所示:

@Configuration 
@EnableTransactionManagement 
@EnableJpaRepositories(basePackages = { 
     "com.automation.entity" 
}) 
public class DataAccessPersistenceContext { 

    @Bean 
    public DataSource sybaseDataSource() { 
     DataSource sybaseDataSource = new DataSource(); 
     try { 
      sybaseDataSource.setDriverClassName("com.sybase.jdbc4.jdbc.SybDriver"); 
      sybaseDataSource.setUrl("jdbc:sybase:Tds:test.com:29812/TESTSCORE"); 
      sybaseDataSource.setUsername("testUser"); 
      String password = "user"; 
      sybaseDataSource.setPassword(password); 
      sybaseDataSource.setInitialSize(Integer.parseInt("5")); 
      sybaseDataSource.setMaxActive(Integer.parseInt("30")); 
      sybaseDataSource.setMaxIdle(Integer.parseInt("2")); 
      sybaseDataSource.setMinIdle(Integer.parseInt("2")); 
      sybaseDataSource.setValidationQuery("SELECT 1"); 
      sybaseDataSource.setTestOnBorrow(Boolean.parseBoolean("true")); 
      sybaseDataSource.setTestWhileIdle(Boolean.parseBoolean("true")); 
     } catch (NumberFormatException e) { 
      // log.error("Exception in CoreLocalConfig. 
      // NumberFormatException:"+e); 
     } catch (Exception e) { 
      // log.error("Exception in CoreLocalConfig. Exception:"+e); 
     } 
     return sybaseDataSource; 
    } 

    @Bean 
    @Qualifier("entityManagerFactory") 
    LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { 
     LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); 
     entityManagerFactoryBean.setDataSource(dataSource); 
     entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); 
     entityManagerFactoryBean.setPackagesToScan("com.automation.entity"); 

     Properties jpaProperties = new Properties(); 

     //Configures the used database dialect. This allows Hibernate to create SQL 
     //that is optimized for the used database. 
     jpaProperties.put("hibernate.dialect", "org.hibernate.dialect.Sybase11Dialect"); 

     //Specifies the action that is invoked to the database when the Hibernate 
     //SessionFactory is created or closed. 
     jpaProperties.put("hibernate.hbm2ddl.auto", "create-drop"); 

     //Configures the naming strategy that is used when Hibernate creates 
     //new database objects and schema elements 
     jpaProperties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy"); 

     //If the value of this property is true, Hibernate writes all SQL 
     //statements to the console. 
     jpaProperties.put("hibernate.show_sql", "true"); 

     //If the value of this property is true, Hibernate will format the SQL 
     //that is written to the console. 
     jpaProperties.put("hibernate.format_sql", "true"); 

     entityManagerFactoryBean.setJpaProperties(jpaProperties); 

     return entityManagerFactoryBean; 
    } 

    @Bean 
    JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { 
     JpaTransactionManager transactionManager = new JpaTransactionManager(); 
     transactionManager.setEntityManagerFactory(entityManagerFactory); 
     return transactionManager; 
    } 
} 

能否請你幫我解決這個問題?

+0

可能複製解決它:http://stackoverflow.com/questions/16979586/nullpointerexception-thrown-by-charset-availablecharsets-due-to-our -sybase-JDBC – alfcope

回答

0

我已經加入正確jconnect4.jar文件到classpath中