发表于: 2017-07-28 21:04:08

1 929


今天完成的事情:

1、添加合作公司列表接口,要求认证在前未认证在后,按时间排序。

2、下午编写了新增article和upload接口。
3、讲了小课堂。

明天计划的事情: 

1、article 接口。

2、准备下周可能的面试。
遇到的问题:
1、jetty 插件奏效了,开发 web 项目时能够进行热部署。

jetty-maven-plugin 是一个maven 插件,它能够周期性地检查项目内容,发现变更后自动更新到内置的 Jetty Web 容器中。

通常情况下,我们只需要直接在 IDE 中修改代码,IDE 能够自动执行编译,jetty-maven-plugin 发现编译后的文件变化后,自动将其更新到Jetty容器。

之前我不是没有使用这个jetty插件,早在任务二中就用了。可是在修改代码后,仍然需要启动jetty,这太令人不爽了。

通常我的步骤是,

①建立项目时就在pom中配置jetty插件,设置了 scanIntervalSeconds 值。

<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
   <webApp>
       <contextPath>/</contextPath>
   </webApp>

   <scanIntervalSeconds>0</scanIntervalSeconds>

   <scanTargetPatterns>
       <scanTargetPattern>
           <directory>src/main/webapp</directory>
           <includes>
               <include>**/*.xml</include>
               <include>**/*.properties</include>
           </includes>
       </scanTargetPattern>
   </scanTargetPatterns>

②以maven方式启动jetty。

③开始搬砖,修改了代码,幻想着能够热部署。

④于是按 ctrl+F9 编译(idea不会自动编译代码,需要程序员手动编译)后,但控制台提示 “Hot swapped failed , Operation not supported by VM”。此时访问那个被修改的controller,发现页面已经报错了(是的,连原本的代码都访问不到,直接报404)。


将这个“Hot swapped failed , Operation not supported by VM”谷歌了一下。

https://gist.github.com/naaman/1053217 按照这个教程重新配置了。

发现人家多了一步

  1. Click the Runner tab
  2. In VM Parameters, enter -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000. Note: the address here corresponds to the port you will debug with. Using 4000 leaves the more standard 5005 debug port open for other debuggers.


也就是如下图,

然后检查一下 idea 的 settings 中关于debugger的配置。

测试,先编写一个接口,访问路径为“/a/u/test”,启动服务器,访问之,

@RequestMapping(value = "/a/u/test", method = RequestMethod.GET)
public String test(){

System.out.println("abcdef");

   return null;
}

然后修改了一下、改为打印出“abcc”。

System.out.println("abc");

按ctrl+F9进行编译,会看到提示“1 class reloaded”,好像可以了。

再访问一下,成功了,这行真正体验到了热部署的便捷。

收获:

1、通过讲小课堂 清楚理解了spring的两种注入方式autowird 与自动装配。明白了@autowired 与 @resource 的区别。一个是默认按类型装配,后者默认按名称装配。 



返回列表 返回列表
评论

    分享到