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