话说昨天好好的普通Maven构建项目踩坑完后,今天继续。


之前看《Spring in action》第三版和第四版时发现,第三版是基于xml配置,第四版用了注解。不过书讲的感觉好复杂。我就想跑个简单的例子运行一下。

然后找到这个。http://o7planning.org/web/fe/default/en/document/8108/spring-mvc-tutorial-for-beginners


创建时用了maven的archetype。会发现虽然eclipse没有帮你创建java目录,自己在main文件夹下创建java文件夹后,刷新并没有出现这样的目录结构。我的工程里面还是仅仅只有src/main/resources



接下来我就蛋疼了,没有这个目录,我无法创建package。

此时spring的 <context:component-scan base-package="" /> 根本就无法扫描。


然后尝试不用archetype,虽然有了上面那种目录结构,最后build用tomcat跑起来的时候确实一片空白。

这种坑真的是纠结死人。


纠结到头之后只好换种思路,看看别人是怎么在Eclipse中使用Maven的archetype的。

最后eclipse集成maven3后,创建java项目详细图解看到了问题所在。


原因是new Source Folder了,然后我直接new了个src/main/java

如果提示已经存在还有另外一种方法:在resources直接new folder。



再创建mymvc这个package。

组件扫描,  <context:component-scan base-package="mymvc" />


最后成功使用了SpringMVC进行跳转。

GitHub 加速计划 / ma / maven
36
3
下载
Maven: Apache Maven是一个开源的项目管理和构建工具,主要用于Java项目。适合需要自动化项目构建和依赖管理的开发者。特点包括约定优于配置、易于使用和社区驱动。
最近提交(Master分支:3 个月前 )
29349bb8 Bumps [net.sourceforge.pmd:pmd-core](https://github.com/pmd/pmd) from 7.19.0 to 7.20.0. - [Release notes](https://github.com/pmd/pmd/releases) - [Commits](https://github.com/pmd/pmd/compare/pmd_releases/7.19.0...pmd_releases/7.20.0) --- updated-dependencies: - dependency-name: net.sourceforge.pmd:pmd-core dependency-version: 7.20.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 3 天前
74ef1276 Maven 4.x introduces a unified <sources> element that supports modular project layouts (src/<module>/<scope>/<lang>). However, resource handling did not follow the modular layout - resources were always loaded from the legacy <resources> element which defaults to src/main/resources. This change implements automatic module-aware resource injection: - Detect modular projects (projects with at least one module in sources) - For modular projects without resource configuration in <sources>, automatically inject resource roots following the modular layout: src/<module>/main/resources and src/<module>/test/resources - Resources configured via <sources> take priority over legacy <resources> - Issue warnings (as ModelProblem) when explicit legacy resources are ignored Example: A project with modular sources for org.foo.moduleA will now automatically pick up resources from: - src/org.foo.moduleA/main/resources - src/org.foo.moduleA/test/resources This eliminates the need for explicit maven-resources-plugin executions when using modular project layouts. 4 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐