在公司内网环境下用Intellij IDEA创建springboot项目的相关配置

刚使用IDEA工具编程,在此记录一下自己创建时遇到的所有问题及解决的过程。

在公司内网环境中需要使用代理才能访问外网的情况下。

一、首先设置setting.xml 加入

 

setting.xml

   
      optional
      true
      http
      proxyuser

      proxypass

   

      proxy.host.net

   

      80
      local.net|some.host.com

   

 

 

 

     
      mirrorId
      repositoryId
      Human Readable Name for this Mirror.
      http://maven.aliyun.com/nexus/content/groups/public
   

 

二、设置Maven如图

做完以上的步骤后,maven配置完成。下面创建Maven项目。

三、创建Maven项目

之后给项目起名字,没什么注意的地方,一路点击NEXT,创建成功,如图:

 

四、导包(由于属于内网环境,虽然配置了代理,有时也可能会失败,在此我选择手动导包)

1.在src的同级目录下创建Lib文件夹,用于保存手动导入的jar包,将下载好的jar包复制到lib文件夹中,

回到IDEA如图所示。

   

此时jar包还不能使用,需要在导入。请参考http://blog.csdn.net/a153375250/article/details/50851049

导包成功后如图,导入的jar包可以打开了。

此时基础已经完成了。

五、配置spring和Mybatis配置文件

下面是配置文件的详细内容:

 

config.properties
driverclass=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:SID
username=test
password=test01
maxActive=100
maxWait=5000
initialSize=10
minIdle=1
mybatis-config.xml
 
xml version="1.0" encoding="UTF-8" ?>
 configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<mappers>
    
    <mapper resource="mappers/CyOUserExtendMapper.xml">mapper>
mappers>
configuration>
spring-mybatis.xml
xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       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-4.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/util
       http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    
    <context:component-scan base-package="dao" />
    
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:config.properties" />
    bean>
    
    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName" value="${driverclass}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
        
        <property name="initialSize" value="${initialSize}" />
        
        <property name="maxActive" value="${maxActive}"/>
        
        <property name="minIdle" value="${minIdle}" />
        
        <property name="maxWait" value="${maxWait}"/>
    bean>

    
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        
        
        
        <property name="configLocation" value="classpath:mybatis-config.xml">property>
    bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="dao.AbstractClass" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory">property>
    bean>
    
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    bean>
    <bean id="CyOUserExtendMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
        
        <property name="mapperInterface" value="dao.CyOUserExtendMapper">property>
        <property name="sqlSessionFactory" ref="sqlSessionFactory">property>
    bean>
beans>
CyOUserExtendMapper.xml
xml version="1.0" encoding="UTF-8" ?>
 mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.AbstractClass.CyOUserExtendMapper">
    
  
    <select id="selectAll" parameterType="Object" resultType="dao.entity.Cy_O_User_Extend">
        SELECT * FROM 表名
    select>

mapper>

测试:

test.class
import dao.CyOUserExtendMapper;
import entity.Cy_O_User_Extend;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;


public class test{

    @Test
    public void testSpring_My(){
        ApplicationContext ac=new ClassPathXmlApplicationContext(new String[] {"spring-mybatis.xml"});
        CyOUserExtendMapper coued=(CyOUserExtendMapper) ac.getBean("CyOUserExtendMapper");
        List cy_o_user_extendList=coued.selectAll();
        for (Cy_O_User_Extend coue: cy_o_user_extendList) {
            System.out.println(coue);
            break;
        }
    }
}

你可能感兴趣的:(IDEA相关系列)