转投Idea

Eclipse出现问题

在前两天BuildShip升级后就出现问题,导致Eclipse中使用Gradle不方便,算了直接试试神器Intellij Idea吧。之前各版本信息:Eclipse(Version: Neon.2 Release (4.6.2)),BuildShip(Version: 2.0.0.v20170111-2019),Gradle(Version: 3.3)

转向Idea

好嘛,直接导入build.gradle就好了。如果之前不是用Gradle创建的工程,直接在项目目录下加入build.gradle重新导入就可以正常工作。之前在Eclipse中的build.gradle,供以后参考 :)

build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'

sourceCompatibility = 1.8
webAppDirName = 'WebContent'

sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'resources'
}
}
test {
java {
srcDir 'test'
}
}
}

eclipse {
wtp {
facet {
facet name: 'jst.web', version: '3.1'
facet name: 'jst.java', version: '1.8'
}
}
}

repositories {
jcenter()
}

dependencies {
compile "org.slf4j:slf4j-api:$slf4jVersion"
compile "org.slf4j:jcl-over-slf4j:$slf4jVersion"
compile "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
compile "org.apache.logging.log4j:log4j-web:$log4jVersion"

compile "org.springframework:spring-webmvc:$springVersion"
compile "org.springframework:spring-context-support:$springVersion"
compile "org.springframework:spring-orm:$springVersion"

//compile "org.springframework:spring-aop:$springVersion"
//compile "org.aspectj:aspectjweaver:$aspectJ"
compile "org.aspectj:aspectjrt:$aspectJ"

compile "org.springframework.security:spring-security-web:$springSecurityVersion"
compile "org.springframework.security:spring-security-config:$springSecurityVersion"
compile "org.thymeleaf:thymeleaf-spring4:$thymeleafVersion"

// compile "org.springframework.data:spring-data-jpa:$springDataJpaVersion"
compile "org.mybatis:mybatis:$mybatis"
compile "org.mybatis:mybatis-spring:$mybatisSpring"
// compile "com.h2database:h2:$h2Version"
compile "mysql:mysql-connector-java:$mysqlConnectorVersion"
// compile "org.hibernate:hibernate-core:$hibernateVersion"
compile "org.apache.commons:commons-dbcp2:$dbcp2Version"
// compile "net.sf.ehcache:ehcache:$ehcacheVersion"

// providedRuntime "javax.servlet.jsp.jstl:jstl:$jstlVersion"

// compile "org.apache.taglibs:taglibs-standard-impl:$taglibVersion"
compile "org.hibernate:hibernate-validator:$hibernateVersion"
compile "org.apache.commons:commons-lang3:$commonsLangVersion"

compile "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"

providedRuntime "javax.servlet:javax.servlet-api:$servletVersion"
// compile "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:$jstlApiVersion"
// providedRuntime "javax.el:javax.el-api:$jspElVersion"

testCompile "junit:junit:$junitVersion"
testCompile "org.springframework:spring-test:$springVersion"

configurations.all {
exclude group: "commons-logging", module: "commons-logging"
}
}

这个。。。Eclipse和Idea中的目录结构差别有一些,慢慢适应吧,哈哈。

Idea中MyBatis Mapper.xml问题

Eclipse的时候,Mapper.xmlMapper.java在一起,直接扫包就OK。转到Idea后,半天没搞定,怀疑是Mapper没有读取。然后试着在Mapper.java中使用Annotation,可以正常使用。然后又放狗狗搜了搜,发现是Idea的事情,编译打包的时候不会把Mapper.xml打包,直接将这对基友分开吧,换个地方。放到resources/mapper下面,再扫这个目录。喜欢将把SQL语句和程序分开,所以用Mapper.xml,在Mapper.java里Annotation写SQL语句感觉太乱,看着不舒服斯基。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) throws IOException {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setTypeAliasesPackage("com.liangwu.combustioncal.model");
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:mapper/**/*.xml"));
return sqlSessionFactoryBean;
}

@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}

Gradle打包

之前用Hibernate的时候,我这个小项目打包后31M,每次一点小改动,在本机编译,然后scp到远程VPS上,那个速度慢啊,后来又试着将war包放到七牛上,上传速度倒是很快,VPS下载速度也就100多点,不爽。后来换成MyBatis,包小了一半,但还是有16M,也不是太好用。其实Gradle本来就是用来打包的嘛,上网看了看,然后在VPS上又建了一个仓,以后改完直接push后,再gradle build war,蛮爽。后来想直接用git hooks来完成自动布置,可惜失败了。过段时候好好看看Gradle的使用,看看能不能实现。