我的应用程序中堆满了spring boot,它不想运行模式或表,只想连接到我的数据库SQL Server和查询信息,所以我在文件application.properties中禁用了这一行
spring.batch.initialize-schema=never spring.datasource.initialization-mode=never
但是不工作,我不知道什么是错的,已经配置了我的数据源,提前谢谢,我希望有人能帮助我,对不起我的英语很差。
我使用的是spring boot 2.2.6,我的DataSourceConfiguration代码
..... @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) public class DataSourceConfiguration { @Bean @Primary @Qualifier("jobsDataSource") public DataSource hsqldbDataSource() throws SQLException { final SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriver(new org.hsqldb.jdbcDriver()); dataSource.setUrl("jdbc:hsqldb:mem:mydb"); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; } @Bean public JdbcTemplate jdbcTemplate(final DataSource dataSource) { return new JdbcTemplate(dataSource); } @Bean @Qualifier("sqlserverDataSource") public DataSource sqlserverDataSource() throws SQLException { final SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriver(new net.sourceforge.jtds.jdbc.Driver()); dataSource.setUrl("jdbc:jtds:sqlserver://x.y.z.t:1433/mydb"); dataSource.setUsername("usersqlserver"); dataSource.setPassword("xxxxxx"); return dataSource; } @Bean public JdbcTemplate sqlJdbcTemplate(@Qualifier("sqlserverDataSource") final DataSource dataSource) { return new JdbcTemplate(dataSource); } public PlatformTransactionManager transactionManager(){ return new ResourcelessTransactionManager(); } @Bean public BatchConfigurer configurer(@Qualifier("sqlserverDataSource") DataSource dataSource){ return new DefaultBatchConfigurer(){ @Override protected JobRepository createJobRepository() throws Exception { JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean(); factory.setDataSource(dataSource); factory.setTransactionManager(transactionManager()); return factory.getObject(); // MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(transactionManager()); // mapJobRepositoryFactoryBean.setTransactionManager(transactionManager()); // return mapJobRepositoryFactoryBean.getObject(); } @Override protected JobLauncher createJobLauncher() throws Exception { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(createJobRepository()); jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor()); jobLauncher.afterPropertiesSet(); return jobLauncher; } }; } }
这里是错误
Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested exception is java.sql.SQLException: Invalid object name 'BATCH_JOB_INSTANCE'. at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:235) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1443) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:700) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:712) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:768) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.getJobInstance(JdbcJobInstanceDao.java:151) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.batch.core.repository.support.SimpleJobRepository.isJobInstanceExists(SimpleJobRepository.java:91) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366) ~[spring-tx-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at com.sun.proxy.$Proxy54.isJobInstanceExists(Unknown Source) ~[na:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE] at com.sun.proxy.$Proxy46.isJobInstanceExists(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.getNextJobParameters(JobLauncherCommandLineRunner.java:199) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE] at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:191) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE] at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:166) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE] at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:153) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE] at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:148) ~[spring-boot-autoconfigure-2.2.6.RELEASE.jar:2.2.6.RELEASE] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) [spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE] ... 10 common frames omitted Caused by: java.sql.SQLException: Invalid object name 'BATCH_JOB_INSTANCE'. at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372) ~[jtds-1.3.1.jar:1.3.1] at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988) ~[jtds-1.3.1.jar:1.3.1] at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421) ~[jtds-1.3.1.jar:1.3.1]
提前致谢
好的,我已经删除了这行,我照您的建议做了,它起作用了,只是dao是NullpointerException,它是接口,并且在ItemProcessor:中使用
@Bean
public BatchConfigurer configurer(@Qualifier("sqlserverDataSource") DataSource dataSource){
return new DefaultBatchConfigurer(){
// @Override
// protected JobRepository createJobRepository() throws Exception {
// JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
// factory.setDataSource(dataSource);
// factory.setTransactionManager(transactionManager());
// // factory.setIsolationLevelForCreate("ISOLATION_READ_COMMITTED");
// //factory.setTablePrefix("dbo.tmpAccWebServ");
// //factory.setDatabaseType("SQLSERVER");
// //factory.setMaxVarCharLength(1000);
// return factory.getObject();
//// MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(transactionManager());
//// mapJobRepositoryFactoryBean.setTransactionManager(transactionManager());
//// return mapJobRepositoryFactoryBean.getObject();
// }
//
// @Override
// protected JobLauncher createJobLauncher() throws Exception {
// SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
// jobLauncher.setJobRepository(createJobRepository());
// jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
// jobLauncher.afterPropertiesSet();
// return jobLauncher;
// }
@Override
public void setDataSource(DataSource dataSource) {
// override to do not set datasource even if a datasource exist.
// initialize will use a Map based JobRepository (instead of database)
} //
};
}//
这是CustomerItemProcessor
的代码
public class CustomerItemProcessor implements ItemProcessor<beangenerico,ThreadLocal<CopyOnWriteArrayList<beanCustomer>>> {
@Autowired
private CustomerDAO customerDAO;
private ThreadLocal<CopyOnWriteArrayList<beanCustomer>> listbean = new ThreadLocal<CopyOnWriteArrayList<beanCustomer>>();
public ThreadLocal<CopyOnWriteArrayList<beanCustomer>> process(beangenerico rangos) throws Exception {
System.out.println("entro a customitemprocessor");
listbean.set(new CopyOnWriteArrayList<beanCustomer>());
System.out.println("rangos:"+rangos.getIni()+"-"+rangos.getFin());
listbean = customerDAO.getAccAgentes(rangos);
if(listbean != null) {
//customer.setId(currentCustomer.getId());
return listbean;
} else {
return null;
}
}
@Autowired
public void setCustomerDAO(CustomerDAOImpl customerDAO) {
this.customerDAO = customerDAO;
}
}
这是接口的代码
public interface CustomerDAO {
ThreadLocal<CopyOnWriteArrayList<beanCustomer>> getAccAgentes(beangenerico bean);
}
这是CustomerDAOImpl
的代码
@Repository
@Component
public class CustomerDAOImpl implements CustomerDAO{
private String SP_SQL = "{call mysp(?, ?)}";
@Autowired
@Qualifier("sqlserverDataSource")
DataSource dataSource;
@Autowired
JdbcTemplate jdbcTemplate;
public ThreadLocal<CopyOnWriteArrayList<beanCustomer>> getAccAgentes(beangenerico bean) {
...
//query resulset
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
}
事先谢谢你的帮助。
spring批处理需要您的数据库中的几个表才能运行。所以你需要在前面手动创建这些表,或者告诉spring boot为你做这件事。
既然您告诉spring boot不要通过设置Spring.batch.initialize-schema=never
来为您创建这些表,那么您需要自己在目标数据源中创建它们。
因此,在您的情况下,在运行作业之前,需要运行DDL脚本在SQL server实例上创建spring批处理表。
我创建了一个spring批处理来查询Azure SQL server数据库并将数据写入CSV文件。我没有数据库的权限。运行批处理时,我得到以下错误。我不希望在主数据库中创建spring批处理元数据表。或者,如果我可以将它们放在另一个本地或内存中的db中,比如h2db,也会很有帮助。我还添加了,这里的大多数类似问题的答案都是这样的,但这没有帮助。 编辑: 我通过扩展类并重写方法,从而在内存映射存储库
Java程序的一个思路如下: 我期望输出如下: 但是得到 显然,try块正在抛出一个ClassNotFoundExcure,这是出乎意料的。你知道为什么代码会抛出这个而不是像预期的那样初始化Gum类吗?
问题内容: 在SQL Server 2016中,我收到带有STRING_SPLIT函数的错误 错误: 无效的对象名称“ STRING_SPLIT”。 问题答案: 确保数据库兼容性级别为 130 您可以使用以下查询对其进行更改:
主要内容:创建别名,删除别名,替换别名别名表示现有命令创建快捷键或关键字。 假设想要执行下面的命令,不是使用选项的目录列表命令,而不是在目录列表中显示所有必要的细节。 假设如果要创建这个命令的快捷方式如下。 当要执行命令时,可以简单地键入这个单词。这个词现在已经成为命令的别名。 创建别名 别名通过使用命令进行管理。 语法 其中, macroname - 宏的简称。 text - 要调用的命令。 以下是命令的选项的说明。 编号 选项 描
本文向大家介绍非对称和对称多处理之间的区别,包括了非对称和对称多处理之间的区别的使用技巧和注意事项,需要的朋友参考一下 非对称多处理 非对称多处理是使用由一个主处理器处理的两个或多个处理器。所有CPU都是互连的,但不是自调度的。AMP用于根据任务的优先级和重要性将特定任务调度到CPU。 对称多处理 对称多处理是使用两个或多个共享公共内存空间的自调度处理器。每个处理器都可以访问I / O和存储设备。
我创建了一个基本的.NET framework MVC web应用程序,并添加了使用Cloud Watch logs SDK向AWS Cloud Watch logs发送日志的逻辑,它在LocalSystem/LocalHost中运行良好,但当我对映像进行对接时,就开始出现异常。请指导我解决这个问题。 Amazon.Runtime.AmazonServiceException:“引发了状态为Nam