发表于: 2018-03-10 22:19:31

1 564


今日完成

1.整合sprng+mybatis

 (1)网上查找资料:

    @RunWith(JUnit4.class)就是指用JUnit4来运行

    @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境

    @RunWith(Suite.class)的话就是一套测试集合

     


  (2) a.@Controller    控制层,就是我们的action层

        b.@Service      业务逻辑层,就是我们的service或者manager层

        c.@Repository:持久层,就是我们常说的DAO层。它用于将数据访问层(DAO 层)的类标识为Spring Bean。具体只需将该注解标注在DAO类上即可。同时,为了让Spring能够扫描类路径中的类并识别出@Repository注解,需要在XML配置文件中启用Bean的自动扫描功能,这可以通过<context:component-scan/>实现。 

@Repository只能标注在DAO类上呢?这是因为该注解的作用不只是将类识别为Bean,同时它还能将所标注的类中抛出的数据访问异常封装为Spring的数据访问异常类型。Spring本身提供了一个丰富的并且是与具体的数据访问技术无关的数据访问异常结构,用于封装不同的持久层框架抛出的异常,使得异常独立于底层的框架。

        d.@Component  (字面意思就是组件),它在你确定不了事哪一个层的时候使用。

其实,这四个注解的效果都是一样的,spring都会把它们当做需要注入的Bean加载在上下文中;

但是在项目中,却建议你严格按照除Componen的其余三个注解的含义使用在项目中。这对分层结构的web架构很有好处。

通过在类上使用@Repository、@Component、@Service和@Constroller注解,Spring会自动创建相应的BeanDefinition对象,并注册到ApplicationContext中。这些类就成了Spring受管组件。这三个注解除了作用于不同软件层次的类,其使用方式与@Repository是完全相同的。

      <context:component-scan base-package=" "/>扫描指定路径的包,如果某个类的头上带有特定的注解

     @Component,@Repository,@Service,@Controller,就会将这个对象作为Bean注入进spring容器。


     然后更改bean.xml,成功运行

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
   <!--加载properties文件,获取数据库连接的一些信息-->
   <context:annotation-config/>
   <context:component-scan base-package="com"/>
   <mvc:annotation-driven/>
   <!--<context:property-placeholder location="db.properties"/>-->
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
       <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
       <property name="url" value="jdbc:mysql://localhost:3306/wodeshujuku"/>
       <property name="username" value="root"/>
       <property name="password" value="w7217459"/>
       <!--<property name="maxActive" value="10"/>
       <property name="maxIdle" value="5"/>-->
   </bean>
   <!--使用类构造器实例化bean,class属性表示要使用的类的全限定名 -->
   <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
       <!-- 加载数据源,使用上面配置好的数据源 -->
       <property name="dataSource" ref="dataSource"/>
       <!-- 加载mybatis的全局配置文件,放在classpath下的mybatis文件夹中了 -->
       <property name="mapperLocations" value="StudentMapper.xml"/>
       <property name="typeAliasesPackage" value="com.POJO"/>
   </bean>

   <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
       <property name="basePackage" value="com.DAO"/>
       <!--<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>-->

   </bean>
</beans>


然后将上面的配置引入到之前写的web项目中,反复尝试不成功,检查后发现,配置正确。然后创建了个测试类,检测是否配置成功。经过验证,配置无误。web项目中不成功运行的原因猜想:

   a.web项目配置应该有相应更改,今天未进行检查;

 2.下午看老大直播

   a.入职前需要准备什么

   b.身份证原件,复印件。

   c.离职证明

   d.学历,学位证书

   e.免冠照

   f.以及招聘方的特殊要求

    为什么要准备其中的c和f:
       c项:让面试官知道你以前就是在这个行业工作。如果不是应届生这之间应聘成功的概率差距很大;

       f项:面试之前可能会要求做一些demo,而且我们也需要从网上了解招聘方的主要业务内容,以此做出相应准备;


明天计划

明天请假,后天计划:

springMVC的学习

RESTful的学习;

遇到问题

在pom中重复导入了jar包,运行时报错:

Some problems were encountered while building the effective model for com.paas.cas:cas-web:war:0.0.1-SNAPSHOT

[WARNING] 'dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.security:spring-security-core:jar -> duplicate declaration of version ${spring.security.core.version} @ com.paas:pms:0.0.1-SNAPSHOT, 

解决方法:检查pom.xml文件,删除报错中提到的重复的jar包;

还有些其他坑遇到了,但是未记录下来,但是都依次解决了;

收获

   看了老大的直播,对以后求职方向更为清晰。

   昨天留下的问题解决了。


返回列表 返回列表
评论

    分享到