From bebe7c159f00e6d5a83bb786824d5f32e4de9270 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 24 Feb 2018 16:54:28 +0300 Subject: spring boot wip --- juick-server-jdbc/build.gradle | 37 +++++++++++----------- .../com/juick/configuration/DataConfiguration.java | 9 +++--- .../configuration/RepositoryConfiguration.java | 10 ------ .../java/com/juick/service/MessageServiceTest.java | 9 +++--- 4 files changed, 27 insertions(+), 38 deletions(-) (limited to 'juick-server-jdbc') diff --git a/juick-server-jdbc/build.gradle b/juick-server-jdbc/build.gradle index 76a37e4b..f17398b6 100644 --- a/juick-server-jdbc/build.gradle +++ b/juick-server-jdbc/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'java' -apply plugin: 'war' +apply plugin: 'io.spring.dependency-management' sourceCompatibility = 1.8 @@ -12,42 +12,43 @@ dependencies { compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${rootProject.jacksonVersion}" compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${rootProject.jacksonVersion}" - providedCompile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}" - providedCompile "ch.qos.logback:logback-core:${rootProject.logbackVersion}" - providedCompile "ch.qos.logback:logback-access:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-classic:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-core:${rootProject.logbackVersion}" + compile "ch.qos.logback:logback-access:${rootProject.logbackVersion}" - providedCompile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:slf4j-api:${rootProject.slf4jVersion}" + compile "org.slf4j:jcl-over-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:log4j-over-slf4j:${rootProject.slf4jVersion}" + compile "org.slf4j:jul-to-slf4j:${rootProject.slf4jVersion}" - providedCompile "org.apache.commons:commons-lang3:3.7" - providedCompile "org.apache.commons:commons-collections4:4.1" + compile "org.apache.commons:commons-lang3:3.7" + compile "org.apache.commons:commons-collections4:4.1" - compile "org.springframework:spring-context:${rootProject.springFrameworkVersion}" - compile "org.springframework:spring-jdbc:${rootProject.springFrameworkVersion}" + compile("org.springframework.boot:spring-boot-starter-jdbc") - providedCompile "org.apache.commons:commons-dbcp2:2.2.0" + compile "org.apache.commons:commons-dbcp2:2.2.0" compile "com.googlecode.log4jdbc:log4jdbc:1.2" compile "javax.inject:javax.inject:1" compile 'org.imgscalr:imgscalr-lib:4.2' - providedCompile 'com.h2database:h2:1.4.196' - providedCompile "javax.servlet:javax.servlet-api:3.1.0" - providedRuntime 'mysql:mysql-connector-java:5.1.40' + compile 'com.h2database:h2:1.4.196' + runtime 'mysql:mysql-connector-java:5.1.40' - providedRuntime "commons-fileupload:commons-fileupload:1.3.3" + runtime "commons-fileupload:commons-fileupload:1.3.3" testCompile project(path: ':juick-core', configuration: 'testArtifacts') testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" testCompile "org.mockito:mockito-core:${rootProject.mockitoVersion}" - testCompile "org.springframework:spring-test:${rootProject.springFrameworkVersion}" + testCompile("org.springframework.boot:spring-boot-starter-test") testRuntime "mysql:mysql-connector-java:5.1.40" testRuntime "org.postgresql:postgresql:42.2.1" } +dependencyManagement { + imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${rootProject.springBootVersion}") } +} compileJava.options.encoding = 'UTF-8' diff --git a/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java b/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java index 2073c3c0..ee9d0baa 100644 --- a/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java +++ b/juick-server-jdbc/src/main/java/com/juick/configuration/DataConfiguration.java @@ -23,8 +23,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.PlatformTransactionManager; @@ -40,7 +40,6 @@ import java.util.List; */ @Configuration @EnableTransactionManagement -@PropertySource(value = {"classpath:juick.conf"}, ignoreResourceNotFound = true) @ComponentScan(basePackages = {"com.juick.service"}) public class DataConfiguration implements TransactionManagementConfigurer { @Value("${datasource_driver:org.h2.Driver}") @@ -246,18 +245,18 @@ public class DataConfiguration implements TransactionManagementConfigurer { " `cnt` smallint(5) unsigned NOT NULL DEFAULT '0'," + " PRIMARY KEY (`user_id`)" + ")"); - jdbcTemplate.execute("CREATE TABLE `auth` (" + + jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS `auth` (" + " `user_id` int(10) unsigned NOT NULL," + " `protocol` enum('xmpp','email','sms') NOT NULL," + " `account` char(64) NOT NULL," + " `authcode` char(8) NOT NULL" + ")"); - jdbcTemplate.execute("CREATE TABLE `mail` (" + + jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS `mail` (" + " `user_id` int(10) unsigned NOT NULL," + " `hash` char(16) NOT NULL," + " PRIMARY KEY (`user_id`)" + ")"); - jdbcTemplate.execute("CREATE TABLE `usersinfo` (" + + jdbcTemplate.execute("CREATE TABLE IF NOT EXISTS `usersinfo` (" + " `user_id` int(10) unsigned NOT NULL," + " `jid` char(32) DEFAULT NULL," + " `fullname` char(32) DEFAULT NULL," + diff --git a/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java b/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java index eac98354..4541da94 100644 --- a/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java +++ b/juick-server-jdbc/src/test/java/com/juick/configuration/RepositoryConfiguration.java @@ -19,23 +19,13 @@ package com.juick.configuration; import com.juick.service.ImagesService; import com.juick.service.MockImagesService; -import com.juick.service.search.SearchService; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.DependsOn; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.DriverManagerDataSource; - -import javax.sql.DataSource; -import java.util.Collections; -import java.util.List; /** * Created by aalexeev on 11/25/16. */ @Configuration -@ComponentScan(basePackages = "com.juick.service") public class RepositoryConfiguration { @Bean public ImagesService imagesService() { diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java index d9f095ac..b082bfd1 100644 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java @@ -26,18 +26,17 @@ import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.TagStats; import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; -import org.junit.*; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import javax.inject.Inject; import java.sql.Timestamp; import java.time.Instant; -import java.time.LocalDateTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -50,7 +49,7 @@ import static org.junit.Assert.assertEquals; /** * Created by aalexeev on 11/25/16. */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @ContextConfiguration(classes = { DataConfiguration.class, RepositoryConfiguration.class }) public class MessageServiceTest extends AbstractJUnit4SpringContextTests { @Inject -- cgit v1.2.3