国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

spring-boot整合Mybatis如何部署在weblogic上

brianway / 1106人閱讀

摘要:介紹本文在參考了如何優雅的在上部署的基礎下使用整合部署在服務器上。在中可以右擊將項目打成包部署測試在上部署應用可以參考部署項目包。總結到這里我們已經成功將和整合并部署到上。

介紹

本文在參考了如何優雅的在weblogic上部署spring-boot的基礎下使用springboot整合Mybatis部署在weblogic服務器上。

環境

開發工具:Eclipse
weblogic版本:10.3.6.0
weblogic-jdk:1.8.0_91

技術實現

創建Maven工程,在pom文件中加入


  4.0.0
  com.ws
  weblogic-test
  0.0.1-SNAPSHOT
  
  
    1.5.4.RELEASE
    UTF-8
  
  
        org.springframework.boot
        spring-boot-starter-parent
        1.5.4.RELEASE
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-jdbc            
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.1.1
            
           
            com.github.pagehelper  
            pagehelper  
            4.2.0  
         
         
         
            com.alibaba
            druid
            1.0.25
        
        
            javax.servlet
            servlet-api
            2.5
            test
        
        
            org.springframework
            spring-messaging
        
        
            javax.servlet
            javax.servlet-api          
            provided
        
        
            org.springframework.boot
            spring-boot-legacy
            1.0.2.RELEASE
         
         
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        
    
    
        
              
                org.apache.maven.plugins
                maven-war-plugin
                
                    true
                    
                        
                            ${project.version}
                        
                        
                            true
                            lib/
                        
                    
                    
                        
                            ${project.basedir}/src/main/resources/static
                        
                        
                            ${project.basedir}/src/main/webapp
                        
                    
                    ${project.artifactId}
                
            

            
                org.springframework.boot
                spring-boot-maven-plugin
                ${spring.boot.version}
                
                    BOOT
                
                
                    
                        
                            repackage
                        
                    
                
            
            
            
                maven-compiler-plugin
                
                    1.6
                    1.6
                
            
        
    

2.創建springboot入口類,配置類和測試類

@SpringBootApplication
@MapperScan("com.ws.mapper")
public class WeblogicTestApplication extends SpringBootServletInitializer implements WebApplicationInitializer{
    public static void main(String[] args) {
        SpringApplication.run(WeblogicTestApplication.class, args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WeblogicTestApplication.class);
    }

配置文件

server.port=8888
logging.level.=INFO
server.tomcat.uri-encoding=UTF-8
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.connection-timeout=5000

spring.resources.static-locations=classpath:static/,file:static/

#spring.devtools.restart.enabled: true

mybatis.configuration.mapUnderscoreToCamelCase=true
mybatis.type-aliases-package=com.df.bean

spring.dataSource.primaryDataSource.type=com.alibaba.druid.pool.DruidDataSource
spring.dataSource.primaryDataSource.url=jdbc:oracle:thin:@10.2.1.242:1521/eaidb
spring.dataSource.primaryDataSource.username=cheryeai_osbmngt
spring.dataSource.primaryDataSource.password=cheryDBeai123
spring.dataSource.primaryDataSource.driverClassName = oracle.jdbc.driver.OracleDriver
spring.dataSource.primaryDataSource.initialSize = 5
spring.dataSource.primaryDataSource.minIdle = 5
spring.dataSource.primaryDataSource.maxActive = 15
spring.dataSource.primaryDataSource.maxWait = 60000
spring.dataSource.primaryDataSource.timeBetweenEvictionRunsMillis = 60000
spring.dataSource.primaryDataSource.minEvictableIdleTimeMillis = 300000
spring.dataSource.primaryDataSource.validationQuery = SELECT 1 FROM DUAL
spring.dataSource.primaryDataSource.testWhileIdle = true
spring.dataSource.primaryDataSource.testOnBorrow = true
spring.dataSource.primaryDataSource.testOnReturn = true

配置數據源

@Component
@ConfigurationProperties(prefix = "spring.dataSource.primaryDataSource")
public class DuridBeans {
    private String type;

    private String url;

    private String username;

    private String password;

    private String driverClassName;

    private Integer initialSize;

    private Integer minIdle;

    private Integer maxActive;

    private Integer maxWait;

    private Integer timeBetweenEvictionRunsMillis;

    private Integer minEvictableIdleTimeMillis;

    private String validationQuery;

    private Boolean testWhileIdle;

    private Boolean testOnBorrow;

    private Boolean testOnReturn;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public Integer getInitialSize() {
        return initialSize;
    }

    public void setInitialSize(Integer initialSize) {
        this.initialSize = initialSize;
    }

    public Integer getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(Integer minIdle) {
        this.minIdle = minIdle;
    }

    public Integer getMaxActive() {
        return maxActive;
    }

    public void setMaxActive(Integer maxActive) {
        this.maxActive = maxActive;
    }

    public Integer getMaxWait() {
        return maxWait;
    }

    public void setMaxWait(Integer maxWait) {
        this.maxWait = maxWait;
    }

    public Integer getTimeBetweenEvictionRunsMillis() {
        return timeBetweenEvictionRunsMillis;
    }

    public void setTimeBetweenEvictionRunsMillis(Integer timeBetweenEvictionRunsMillis) {
        this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    }

    public Integer getMinEvictableIdleTimeMillis() {
        return minEvictableIdleTimeMillis;
    }

    public void setMinEvictableIdleTimeMillis(Integer minEvictableIdleTimeMillis) {
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    }

    public String getValidationQuery() {
        return validationQuery;
    }

    public void setValidationQuery(String validationQuery) {
        this.validationQuery = validationQuery;
    }

    public Boolean getTestWhileIdle() {
        return testWhileIdle;
    }

    public void setTestWhileIdle(Boolean testWhileIdle) {
        this.testWhileIdle = testWhileIdle;
    }

    public Boolean getTestOnBorrow() {
        return testOnBorrow;
    }

    public void setTestOnBorrow(Boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }

    public Boolean getTestOnReturn() {
        return testOnReturn;
    }

    public void setTestOnReturn(Boolean testOnReturn) {
        this.testOnReturn = testOnReturn;
    }

}
@Configuration
public class DuridSource {
     @Autowired
     private DuridBeans druidPrimaryDataSourceConfigProperties;
     @Bean(name="dataSource")
     @Primary
     public DataSource primaryDataSource (){
        DruidDataSource datasource = new DruidDataSource();

        datasource.setUrl(this.druidPrimaryDataSourceConfigProperties.getUrl());
        datasource.setUsername(this.druidPrimaryDataSourceConfigProperties.getUsername());
        datasource.setPassword(this.druidPrimaryDataSourceConfigProperties.getPassword());
        datasource.setDriverClassName(this.druidPrimaryDataSourceConfigProperties.getDriverClassName());


        datasource.setInitialSize(this.druidPrimaryDataSourceConfigProperties.getInitialSize());
        datasource.setMinIdle(this.druidPrimaryDataSourceConfigProperties.getMinIdle());
        datasource.setMaxActive(this.druidPrimaryDataSourceConfigProperties.getMaxActive());
        datasource.setMaxWait(this.druidPrimaryDataSourceConfigProperties.getMaxWait());
        datasource.setTimeBetweenEvictionRunsMillis(this.druidPrimaryDataSourceConfigProperties.getTimeBetweenEvictionRunsMillis());
        datasource.setMinEvictableIdleTimeMillis(this.druidPrimaryDataSourceConfigProperties.getMinEvictableIdleTimeMillis());
        datasource.setValidationQuery(this.druidPrimaryDataSourceConfigProperties.getValidationQuery());
        datasource.setTestWhileIdle(this.druidPrimaryDataSourceConfigProperties.getTestWhileIdle());
        datasource.setTestOnBorrow(this.druidPrimaryDataSourceConfigProperties.getTestOnBorrow());
        datasource.setTestOnReturn(this.druidPrimaryDataSourceConfigProperties.getTestOnReturn());

        return datasource;
    }

}
@Configuration
public class MybatisConfig {
    @Autowired 
    private DataSource dataSource;   //Durid數據源
    
    @Bean
    public SqlSessionFactoryBean createSqlSessionFactoryBean() throws Exception {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); 
    sqlSessionFactoryBean.setDataSource(dataSource); 
    org.apache.ibatis.session.Configuration config=new org.apache.ibatis.session.Configuration();
    config.setMapUnderscoreToCamelCase(true);    //設置駝峰命名
    sqlSessionFactoryBean.setConfiguration(config);
    sqlSessionFactoryBean.setTypeAliasesPackage("com.ws.bean"); 
    Interceptor[] plugins =  new Interceptor[]{pageHelper()};
    sqlSessionFactoryBean.setPlugins(plugins);
    return sqlSessionFactoryBean; 
    }
    
    /**
     * Mybatis分頁插件 
     */
    @Bean
    public PageHelper pageHelper() {
        PageHelper pageHelper = new PageHelper();
        Properties p = new Properties();
        p.setProperty("offsetAsPageNum", "true");
        p.setProperty("rowBoundsWithCount", "true");
        p.setProperty("reasonable", "true");
        pageHelper.setProperties(p);
        return pageHelper;
    }
public interface UserMapper {
    @Select({"SELECT * FROM USER_TEST"})
    List getUserInfo();
}
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    public List getUserInfoSer(){
        return userMapper.getUserInfo();        
    }
}
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value="/test" ,method= RequestMethod.GET)
    public String testGetUserInfo() {
        User user=userService.getUserInfoSer().get(0);
        return "我是"+user.getUserName()+"今年"+user.getUserAge()+"歲了!";
    }
}

說明:關于Durid數據源的配置這里就不詳細說明了,springboot默認使用tomcat的數據源,在使用tomcat數據源部署的時候報錯(NO supported Datasource type found),然后就給換成durid數據源。

3.創建web.xml和weblogic.xml



    
        contextConfigLocation
        com.ws.WeblogicTestApplication
    
    
        org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener
    
    
        appServlet
        org.springframework.web.servlet.DispatcherServlet
        
            contextAttribute
            org.springframework.web.context.WebApplicationContext.ROOT
        
        1
    
    
        appServlet
        /
    

 
    /testweblogic
    
                  
            org.slf4j.*
            org.springframework.*
        
    

說明:關于在eclipse中創建web.xml可以參考解決新建maven工程沒有web.xml的問題
4.打包部署
先在pom.xml中加入war。在eclipse中可以右擊pom.xml->Run As->Maven instal 將項目打成war包

5.部署測試
在weblogic上部署web應用可以參考weblogic部署web項目(war包)。
然后在瀏覽器地址欄訪問項目的測試路徑。

6.總結
到這里我們已經成功將 springboot和mybatis整合并部署到weblogic上。

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/77031.html

相關文章

  • SpringBoot 入門簡介

    摘要:這里使用的是數據庫啟動類上加上注解在啟動類中添加對包掃描掃描多個包下的可以有以下幾種方法掃描會自動加載相關配置,數據源就會自動注入到中,會自動注入到中,可以直接使用。有配置文件下的使用掃描多個包下的可以有以下幾種方法掃描 Spring-Boot 學習筆記 1 Spring-Boot 介紹 1.1 什么是Spring-Boot Spring-Boot是由Pivotal團隊提供的全新框架...

    chuyao 評論0 收藏0
  • Springboot整合Quartz實現動態定時任務

    摘要:本文使用實現對定時任務的增刪改查啟用停用等功能。并把定時任務持久化到數據庫以及支持集群。決定什么時候來執行任務。定義的是任務數據,而真正的執行邏輯是在中。封裝定時任務接口添加一個暫停恢復刪除修改暫停所有恢復所有 簡介 Quartz是一款功能強大的任務調度器,可以實現較為復雜的調度功能,如每月一號執行、每天凌晨執行、每周五執行等等,還支持分布式調度。本文使用Springboot+Myba...

    IamDLY 評論0 收藏0

發表評論

0條評論

brianway

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<