Last active
October 19, 2016 15:03
-
-
Save jbovet/4c04a7183c6f470d8ad67b86d567a060 to your computer and use it in GitHub Desktop.
Spring+CXF+Mybatis Annotation Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spring.datasource.schema=import.sql | |
logging.level.root=INFO | |
logging.level.cl.tuxy.cxf.mapper=DEBUG | |
logging.level.org.mybatis.spring=TRACE | |
cxf.path=/Service | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
ext { | |
springBootVersion = '1.4.1.RELEASE' | |
} | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") | |
} | |
} | |
apply plugin: 'java' | |
apply plugin: 'eclipse' | |
apply plugin: 'spring-boot' | |
jar { | |
baseName = 'springboot-cxf-mybatis' | |
version = '0.0.1-SNAPSHOT' | |
} | |
sourceCompatibility = 1.8 | |
targetCompatibility = 1.8 | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
compile('org.springframework.boot:spring-boot-starter-web') | |
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1') | |
compile('org.apache.cxf:cxf-spring-boot-starter-jaxws:3.1.7') | |
compile('com.h2database:h2:1.4.192') | |
testCompile('org.springframework.boot:spring-boot-starter-test') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table user (id int primary key auto_increment, name varchar, email varchar, age int); | |
insert into user (name, email, age) values ('Chuck Norris', 'chuck@norris', '76'); | |
insert into user (name, email, age) values ('Elmo', 'elmo@muppet.org', '40'); | |
insert into user (name, email, age) values ('Bill Gates', 'bill@microsoft.com', '60'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cl.tuxy.cxf; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
@SpringBootApplication | |
public class SpringApplication { | |
public static void main(String[] args) { | |
SpringApplication.run(BootCxfMybatisApplication.class, args); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cl.tuxy.cxf.model; | |
/** | |
* Created by josebovet on 10/17/16. | |
*/ | |
public class User { | |
private Integer id; | |
private String name; | |
private String email; | |
private Integer age; | |
public Integer getId() { | |
return id; | |
} | |
public void setId(Integer id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
public Integer getAge() { | |
return age; | |
} | |
public void setAge(Integer age) { | |
this.age = age; | |
} | |
@Override | |
public String toString() { | |
return "User{" + | |
"id=" + id + | |
", name='" + name + '\'' + | |
", email='" + email + '\'' + | |
", age=" + age + | |
'}'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cl.tuxy.cxf.mapper; | |
import cl.tuxy.cxf.model.User; | |
import org.apache.ibatis.annotations.Mapper; | |
import org.apache.ibatis.annotations.Select; | |
import java.util.List; | |
/** | |
* Created by josebovet on 10/17/16. | |
*/ | |
@Mapper | |
public interface UserMapper { | |
@Select("SELECT * FROM user") | |
List<User> findAllUsers(); | |
@Select("SELECT * FROM user WHERE ID =#{id}") | |
User findUserById(Integer id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cl.tuxy.cxf.service; | |
import cl.tuxy.cxf.model.User; | |
import javax.jws.WebResult; | |
import javax.jws.WebService; | |
import java.util.List; | |
/** | |
* Created by josebovet on 10/17/16. | |
*/ | |
@WebService(name = "UserService") | |
public interface UserService { | |
@WebResult(name = "userList") | |
List<User> listUsers(); | |
@WebResult(name = "User") | |
User getUserByid(Integer id); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cl.tuxy.cxf.service; | |
import cl.tuxy.cxf.mapper.UserMapper; | |
import cl.tuxy.cxf.model.User; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import javax.jws.WebService; | |
import java.util.List; | |
/** | |
* Created by josebovet on 10/17/16. | |
*/ | |
@WebService(serviceName = "UserService", | |
portName = "UserServicePort", | |
endpointInterface = "cl.tuxy.cxf.service.UserService") | |
public class UserServiceImpl implements UserService { | |
@Autowired | |
UserMapper userMapper; | |
@Override | |
public List<User> listUsers() { | |
return userMapper.findAllUsers(); | |
} | |
@Override | |
public User getUserByid(Integer id) { | |
return userMapper.findUserById(id); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cl.tuxy.cxf.config; | |
import cl.tuxy.cxf.service.UserService; | |
import cl.tuxy.cxf.service.UserServiceImpl; | |
import org.apache.cxf.Bus; | |
import org.apache.cxf.jaxws.EndpointImpl; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; | |
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; | |
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; | |
import javax.sql.DataSource; | |
import javax.xml.ws.Endpoint; | |
/** | |
* Created by josebovet on 10/17/16. | |
*/ | |
@Configuration | |
public class WebServiceConfig { | |
@Autowired | |
private Bus bus; | |
@Bean | |
public UserService userService() { | |
return new UserServiceImpl(); | |
} | |
@Bean | |
public Endpoint userServiceEndPoint() { | |
EndpointImpl userServiceEndPoint = new EndpointImpl(bus, userService()); | |
userServiceEndPoint.setAddress("/UserService"); | |
userServiceEndPoint.publish(); | |
return userServiceEndPoint; | |
} | |
@Bean | |
public DataSource dataSource() { | |
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); | |
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2) | |
.addScript("import.sql") | |
.build(); | |
return db; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment