我在我的stanalone应用程序中使用Springboot Spring JPA . 但我正在跟踪错误:
引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.http.converter.StringHttpMessageConverter]:工厂方法'stringHttpMessageConverter'抛出异常;嵌套异常是org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)中的java.lang.NullPointerException,位于org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ... 69更多引起:java.nio.charset.Charset.access上的java.nio.charset.Charset.put(未知来源)中的java.lang.NullPointerException java.nio.charset.Charset上的$ 200(未知来源) $ 3.run(未知来源)java.nio.charset.Charset $ 3.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.nio.charset.Charset.availableCharsets(Unknown Source)at org .springframework.http.converter.StringHttpMessageConverter . (StringHttpMessageConverter.java:67)org.springframe上的org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration $ StringHttpMessageConverterConfiguration.stringHttpMessageConverter(HttpMessageConvertersAutoConfiguration.java:77) work.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration $ StringHttpMessageConverterConfiguration $$ EnhancerBySpringCGLIB $$ 4ce1453d.CGLIB $ stringHttpMessageConverter在org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration $ StringHttpMessageConverterConfiguration $ 0()$$ EnhancerBySpringCGLIB $$ 4ce1453d $$ FastClassBySpringCGLIB $$ 1235f10b . orvoke()atg.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)位于org.springframework.boot的org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) .autoconfigure.web.HttpMessageConvertersAutoConfiguration $ EnhancerBySpringCGLIB $$ 4ce1453d.stringHttpMessageConverter()at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke (java.lang.reflect.Me中的(未知来源) thod.invoke(未知来源)org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)... 70更多
我的Config类如下:
@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;
}
}
你能帮我解决这个问题吗?
1 回答
我通过将正确的jconnect4.jar文件添加到类路径中来解决它