PetClinic보다 큰 오픈 소스 Spring 샘플 프로젝트가 있습니까?
봄 문서와 PetClinic 샘플 프로젝트를 읽었습니다. Spring으로 이루어진 더 큰 실제 프로젝트를 보는 것과 같습니다. 감사.
저는 백엔드에서 Spring을 많이 사용하는 큰 건강 보험 회사에서 일합니다. 모듈화 된 애플리케이션이 어떻게 구축 되는지 보여 드리겠습니다 .
클래스 디렉토리가없는 스켈레톤 WEB-INF
ar
WEB-INF
web.xml
/**
* Spring related settings file
*/
ar-servlet.xml
web
moduleA
account
form.jsp
moduleB
order
form.jsp
스켈레톤 클래스 디렉토리
classes
/**
* Spring related settings file
*/
ar-persistence.xml
ar-security.xml
ar-service.xml
messages.properties
br
com
ar
web
moduleA
AccountController.class
moduleB
OrderController.class
br
com
ar
moduleA
model
domain
Account.class
repository
moduleA.hbm.xml
service
br
com
ar
moduleB
model
domain
Order.class
repository
moduleB.hbm.xml
service
...
공지 사항은 아래 각 패키지 방법 br.com.ar.web는 matchs WEB-INF / 뷰 디렉토리. Spring MVC에서 설정에 대한 규칙을 실행하는 데 필요한 핵심입니다. 어떻게 ??? ControllerClassNameHandlerMapping에 의존
WEB-INF / ar-servlet.xml 알림 basePackage 속성 은 br.com.ar.view 패키지 에서 @Controller 클래스를 찾습니다 . 이 속성을 사용하면 모듈화 된 @Controller를 빌드 할 수 있습니다.
<!--Scans the classpath for annotated components at br.com.ar.web package-->
<context:component-scan base-package="br.com.ar.web"/>
<!--registers the HandlerMapping and HandlerAdapter required to dispatch requests to your @Controllers-->
<mvc:annotation-driven/>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="basePackage" value="br.com.ar.web"/>
<property name="caseSensitive" value="true"/>
<property name="defaultHandler">
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/view/"/>
<property name="suffix" value=".jsp"/>
</bean>
이제 예를 들어 AccountController를 보겠습니다.
package br.com.ar.web;
@Controller
public class AccountController {
@Qualifier("categoryRepository")
private @Autowired Repository<Category, Category, Integer> categoryRepository;
@Qualifier("accountRepository")
private @Autowired Repository<Account, Accout, Integer> accountRepository;
/**
* mapped To /account/form
*/
@RequestMapping(method=RequesMethod.GET)
public void form(Model model) {
model.add(categoryRepository().getCategoryList());
}
/**
* mapped To account/form
*/
@RequestMapping(method=RequesMethod.POST)
public void form(Account account, Errors errors) {
accountRepository.add(account);
}
}
작동 원리 ???
http://127.0.0.1:8080/ar/ moduleA / account / form .html에 대한 요청을한다고 가정합니다.
Spring은 컨텍스트 경로와 파일 확장자 사이 의 경로를 제거합니다 . 추출 된 경로 를 오른쪽에서 왼쪽으로 읽어 보자
- 양식 메소드 이름
- 컨트롤러 접미사가 없는 정규화되지 않은 계정 클래스 이름
- moduleA의 패키지 추가됩니다 에 basePackage의 특성
번역 된
br.com.ar.web.moduleA.AccountController.form
확인. 그러나 Spring은 어떤 뷰를 보여줄지 어떻게 압니까 ??? 여기를 참조 하십시오
그리고 지속성 관련 문제에 대해 ???
우선, 저장소를 어떻게 구현하는지 여기 에서 확인 하세요 . 각 관련 모듈 쿼리는 관련 저장소 패키지에 저장됩니다 . 위의 골격을 참조하십시오. 다음은 ar-persistence.xml 알림 mappingLocations 및 packagesToScan 속성입니다.
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/dataSource" resource-ref="true">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations">
<util:list>
<value>classpath:br/com/ar/model/repository/hql.moduleA.hbm.xml</value>
<value>classpath:br/com/ar/model/repository/hql.moduleB.hbm.xml</value>
</util:list>
</property>
<property name="packagesToScan">
<util:list>
<value>br.com.ar.moduleA.model.domain</value>
<value>br.com.ar.moduleB.model.domain</value>
</util:list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.validator.autoregister_listeners">false</prop>
</props>
</property>
</bean>
</beans>
Hibernate를 사용하고 있음을 알 수 있습니다. JPA가 올바르게 구성되어야합니다.
트랜잭션 관리 및 컴포넌트 스캐닝 ar-service.xml 알림 aop : pointcut의 표현식 속성에서 br.com.ar 뒤에 두 개의 점이 있습니다 .
br.com.ar 패키지의 모든 패키지 및 하위 패키지
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="br.com.ar.model">
<!--Transaction manager - It takes care of calling begin and commit in the underlying resource - here a Hibernate Transaction -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="repositoryTransactionManagementAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add" propagation="REQUIRED"/>
<tx:method name="remove" propagation="REQUIRED"/>
<tx:method name="update" propagation="REQUIRED"/>
<tx:method name="find*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<tx:advice id="serviceTransactionManagementAdvice" transaction-manager="transactionManager">
<!--Any method - * - in service layer should have an active Transaction - REQUIRED - -->
<tx:attributes>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="servicePointcut" expression="execution(* br.com.ar..service.*Service.*(..))"/>
<aop:pointcut id="repositoryPointcut" expression="execution(* br.com.ar..repository.*Repository.*(..))"/>
<aop:advisor advice-ref="serviceTransactionManagementAdvice" pointcut-ref="servicePointcut"/>
<aop:advisor advice-ref="repositoryTransactionManagementAdvice" pointcut-ref="repositoryPointcut"/>
</aop:config>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
</beans>
테스팅
테스트 주석 @Controller 방법에 참조 여기 방법
웹 레이어 이외. @Before 메소드에서 JNDI 데이터 소스를 구성하는 방법에 주목하십시오.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:ar-service.xml", "classpath:ar-persistence.xml"})
public class AccountRepositoryIntegrationTest {
@Autowired
@Qualifier("accountRepository")
private Repository<Account, Account, Integer> repository;
private Integer id;
@Before
public void setUp() {
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
DataSource ds = new SimpleDriverDataSource(new oracle.jdbc.driver.OracleDriver(), "jdbc:oracle:thin:@127.0.0.1:1521:ar", "#$%#", "#$%#");
builder.bind("/jdbc/dataSource", ds);
builder.activate();
/**
* Save an Account and set up id field
*/
}
@Test
public void assertSavedAccount() {
Account account = repository.findById(id);
assertNotNull(account);
}
}
If you need a suite of tests, do as follows
@RunWith(Suite.class)
@Suite.SuiteClasses(value={AccountRepositoryIntegrationTest.class})
public void ModuleASuiteTest {}
web.xml is shown as follows
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:ar-persistence.xml
classpath:ar-service.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>ar</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ar</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<resource-ref>
<description>datasource</description>
<res-ref-name>jdbc/dataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
I hope it can be useful. Update schema To Spring 3.0. See Spring reference documentation. mvc schema, As far As i know, is supported just in Spring 3.0. Keep this in mind
Some candidates:
AppFuse - In AppFuse, the Spring Framework is used throughout for its Hibernate/iBATIS support, declarative transactions, dependency binding and layer decoupling.
Equinox (a.k.a. AppFuse Light) - a simple CRUD app created as part of Spring Live.
Spring by Example - Various Spring examples plus some downloadable libraries.
Tudu Lists - Tudu Lists is a J2EE application for managing todo lists. It's based on JDK 5.0, Spring, Hibernate, and an AJAX interface (using the DWR framework).
Look at Apache CXF. It uses Spring.
ReferenceURL : https://stackoverflow.com/questions/2604655/any-open-source-spring-sample-project-thats-bigger-than-petclinic
'programing' 카테고리의 다른 글
객체가 Core Data에 존재하는지 여부를 확인하는 가장 빠른 방법은 무엇입니까? (0) | 2021.01.17 |
---|---|
Facebook에 아직 공개 검색 API가 있습니까? (0) | 2021.01.17 |
텍스트 필드 깜박이는 커서 숨기기 (0) | 2021.01.17 |
필요하지 않은 속성이 계속 data-val-required 속성을 가져옵니다. (0) | 2021.01.17 |
jQuery.queue ()를 사용하여 Ajax 요청 대기열 (0) | 2021.01.17 |