JavaEE/J2EE面向对象分层架构与配置策略

0 下载量 65 浏览量 更新于2024-08-30 收藏 181KB PDF 举报
"JavaEE/J2EE面向对象实战之道深入解析了在开发企业级软件中,面向对象(Object-Oriented,OO)思维的重要性。许多人抱怨JavaEE/J2EE配置复杂,但这其实是缺乏OO思维的结果。分层架构是OO在该领域的典型应用,主要包括表现层、业务层和持久层。 在表现层,开发者使用Struts等框架构建ActionForm和标签库,将前端界面的离散数据(如单个字段)封装成业务层的DomainModel,这主要涉及映射配置。这就像将数据打包到对象中,以便在业务逻辑中操作。 持久层则是将DomainModel对象存储到数据库中,早期通过JDBC编程时,需要逐一处理每个字段的保存。然而,O/R mapping框架如Hibernate和EJB的CMP则提供了更高级的映射,自动将对象与数据库结构对应起来,减少了手动操作,但配置仍是关键。这些框架的核心工作仍然是映射配置,目的是确保业务逻辑与对象模型紧密耦合,保持系统的对象导向性。 对于映射配置,一个有效的方法是围绕对象模型进行设计,而非直接基于数据表。这意味着在配置时,应聚焦于对象之间的关系和行为,而不是表结构的具体细节。以Hibernate为例,正确配置意味着根据DomainModel的结构来定义映射规则,而不是反过来。遵循这一原则,可以使配置过程更加简洁且易于理解,从而提升开发效率。 总结来说,JavaEE/J2EE中的复杂配置并非无法克服,通过理解并应用面向对象的原则,特别是对象模型驱动的映射配置,开发者能够更好地驾驭这些技术,实现简单易用的开发体验。那些感到困惑的人往往是因为没有充分利用OO思维来指导他们的工作。通过明确的对象模型导向,开发者能够解决配置难题,提升整个开发过程的灵活性和可维护性。"

我用Spring5的aop应用时报这个错误Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\ecliple\web5\WEB-INF\applicationContext.xml]; nested exception is java.nio.file.NoSuchFileException: WEB-INF\applicationContext.xml,他说我的applicationContext.xml文件不存在,可是我明明有这个文件,另外我的web.xml需要更改吗<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <context-param> <param-name>contextConfigLocation </param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <display-name>Struts2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>

2023-05-30 上传