0
我目前正在从spring文档工作春天你好样本。因为他们正在连接嵌入式数据库,而不是我想配置mysql数据库。 来自git的样本https://github.com/spring-guides/gs-batch-processing.git无法连接弹簧与mysql
请亲引导我一个步骤。
将JDBC驱动程序来的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-batch-processing</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>javax.batch</groupId>
<artifactId>javax.batch-api</artifactId>
<version>1.0.1-b01</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这里是数据库配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/spring" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
</beans>
我在这里缺少什么?但仍然连接到嵌入式hsql数据库。看到下面,
. ____ _ __ _ _
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ))))
' |____| .__|_| |_|_| |_\__, |////
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.2.RELEASE)
2015-04-01 18:10:41.746 INFO 10234 --- [ main] hello.Application : Starting Application v0.1.0 on alaska with PID 10234 (/home/malarvizhi/a/spring/bs2/target/gs-batch-processing-0.1.0.jar started by malarvizhi in /home/malarvizhi/a/spring/bs2)
2015-04-01 18:10:41.822 INFO 10234 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]9c7bcc0: startup date [Wed Apr 01 18:10:41 IST 2015]; root of context hierarchy
2015-04-01 18:10:42.961 WARN 10234 --- [ main] o.s.c.a.ConfigurationClassEnhancer : @Bean method ScopeConfiguration.stepScope 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
2015-04-01 18:10:42.975 WARN 10234 --- [ main] o.s.c.a.ConfigurationClassEnhancer : @Bean method ScopeConfiguration.jobScope 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
2015-04-01 18:10:43.253 INFO 10234 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Creating embedded database 'testdb'
2015-04-01 18:10:43.764 INFO 10234 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from URL [jar:file:/home/malarvizhi/a/spring/bs2/target/gs-batch-processing-0.1.0.jar!/schema-all.sql]
2015-04-01 18:10:43.769 INFO 10234 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from URL [jar:file:/home/malarvizhi/a/spring/bs2/target/gs-batch-processing-0.1.0.jar!/schema-all.sql] in 5 ms.
2015-04-01 18:10:44.269 INFO 10234 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql]
2015-04-01 18:10:44.279 INFO 10234 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql] in 9 ms.
2015-04-01 18:10:44.460 INFO 10234 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2015-04-01 18:10:44.479 INFO 10234 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2015-04-01 18:10:44.492 INFO 10234 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
2015-04-01 18:10:44.628 INFO 10234 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2015-04-01 18:10:44.694 INFO 10234 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{run.id=1}]
2015-04-01 18:10:44.720 INFO 10234 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
Converting (firstName:
@daman它没有工作。你能指导我配置mysql数据库的步骤吗? – Pez 2015-04-06 05:30:52
我建议确保你在pom.xml中获得正确的依赖关系。这可能会帮助[链接](http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.6)。在你的数据源中,你配置正确吗?确保你已经下载了mysql-connector-bin.jar文件。我会说这个问题将会进入数据源或依赖关系。但是,您可以发布错误/异常消息吗?现在我假设你无法连接到数据库。确保你的数据库中有弹簧模式。 – Darpan27 2015-04-07 14:30:30