grails使用的疑惑和对web.xml,grails.xml的理解
grails使用的疑惑和对web.xml,grails.xml的理解
lerong_li 发表于1年前
grails使用的疑惑和对web.xml,grails.xml的理解
  • 发表于 1年前
  • 阅读 22
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

傻不拉几的我,一开始总以为web.xml和grails.xml会在项目中,然后我东找西找总是没找到。后来发现,这两个xml是在打包后生成的。

1:web.xml和grails.xml是打包后生成的。

2:grails项目下的web-app目录下的WEB-INF目录下的applicationContext.xml一直都可以看到的。启动的时候进行加载。web.xml启动会加载applicationContext.xml文件

applicationContext.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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!--加载所有的项目中的类到spring中的beanfactory中--->
   <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
      <description>Grails application factory bean</description>
      <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
   </bean>
    <!--加载grails中的插件对应项目中的类到spring中的beanfactory中---> 
   <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
      <description>A bean that manages Grails plugins</description>
      <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
      <property name="application" ref="grailsApplication" />
   </bean>
    <!--加载配置文件,--->
   <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
      <constructor-arg>
         <ref bean="grailsApplication" />
      </constructor-arg>
      <property name="pluginManager" ref="pluginManager" />
   </bean>

   <bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
      <property name="encoding">
         <value>utf-8</value>
      </property>
   </bean>

   <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" />
</beans>

1:我自己在看的过程很多疑惑。比如说dataSoucrce中grails中没进行指派,那么他是如何被加载的呢。后来我看了grails的核心包,包中有个grails-pugin-datasource的jar包,里面会去扫描我们定义的dataSource.groovy文件,并且加载到项目中。

2:对于一个web项目而言,数据源配置是必不可少的。只是现在加载数据源是放在grails核心包里面。大家如果不注意会看不到,

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" metadata-complete="true" version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <display-name>/admin-test-20150731</display-name>
   <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
   </context-param>
   <context-param>
      <param-name>webAppRootKey</param-name>
      <param-value>admin-test-20150731</param-value>
   </context-param>
   <context-param>
      <param-name>sample</param-name>
      <param-value>Sample Value</param-value>
   </context-param>
   <filter>
      <filter-name>springSecurityFilterChain</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      <async-supported>true</async-supported>
   </filter>
   <filter>
      <filter-name>charEncodingFilter</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      <async-supported>true</async-supported>
      <init-param>
         <param-name>targetBeanName</param-name>
         <param-value>characterEncodingFilter</param-value>
      </init-param>
      <init-param>
         <param-name>targetFilterLifecycle</param-name>
         <param-value>true</param-value>
      </init-param>
   </filter>
   <filter>
      <filter-name>AssetPipelineFilter</filter-name>
      <filter-class>asset.pipeline.AssetPipelineFilter</filter-class>
      <async-supported>true</async-supported>
   </filter>
   <filter>
      <filter-name>urlMapping</filter-name>
      <filter-class>org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter</filter-class>
      <async-supported>true</async-supported>
   </filter>
   <filter>
      <filter-name>hiddenHttpMethod</filter-name>
      <filter-class>org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter</filter-class>
      <async-supported>true</async-supported>
   </filter>
   <filter>
      <filter-name>grailsWebRequest</filter-name>
      <filter-class>org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter</filter-class>
      <async-supported>true</async-supported>
   </filter>
   <filter>
      <filter-name>grailsCacheFilter</filter-name>
      <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
      <async-supported>true</async-supported>
      <init-param>
         <param-name>targetFilterLifecycle</param-name>
         <param-value>true</param-value>
      </init-param>
   </filter>
   <filter-mapping>
      <filter-name>charEncodingFilter</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>
   <filter-mapping>
      <filter-name>hiddenHttpMethod</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>AssetPipelineFilter</filter-name>
      <url-pattern>/assets/*</url-pattern>
      <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>grailsWebRequest</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
      <dispatcher>ERROR</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>springSecurityFilterChain</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>ERROR</dispatcher>
      <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>urlMapping</filter-name>
      <url-pattern>/*</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
   <filter-mapping>
      <filter-name>grailsCacheFilter</filter-name>
      <url-pattern>*.dispatch</url-pattern>
      <dispatcher>FORWARD</dispatcher>
      <dispatcher>INCLUDE</dispatcher>
   </filter-mapping>
   <listener>
      <listener-class>org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener</listener-class>
   </listener>
   <listener>
      <listener-class>org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener</listener-class>
   </listener>
   <servlet>
      <servlet-name>grails</servlet-name>
      <servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
      <init-param>
         <param-name>dispatchOptionsRequest</param-name>
         <param-value>true</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
      <async-supported>true</async-supported>
   </servlet>
   <servlet>
      <servlet-name>gsp</servlet-name>
      <servlet-class>org.codehaus.groovy.grails.web.pages.GroovyPagesServlet</servlet-class>
   </servlet>
   <servlet>
      <servlet-name>grails-errorhandler</servlet-name>
      <servlet-class>org.codehaus.groovy.grails.web.servlet.ErrorHandlingServlet</servlet-class>
   </servlet>
   <servlet-mapping>
      <servlet-name>gsp</servlet-name>
      <url-pattern>*.gsp</url-pattern>
   </servlet-mapping>
   <servlet-mapping>
      <servlet-name>grails-errorhandler</servlet-name>
      <url-pattern>/grails-errorhandler</url-pattern>
   </servlet-mapping>
   <servlet-mapping>
      <servlet-name>grails</servlet-name>
      <url-pattern>*.dispatch</url-pattern>
   </servlet-mapping>
   <session-config>
      <session-timeout>30</session-timeout>
   </session-config>
   <welcome-file-list>
      <welcome-file>index.html</welcome-file>
      <welcome-file>index.jsp</welcome-file>
      <welcome-file>index.gsp</welcome-file>
   </welcome-file-list>
   <error-page>
      <error-code>500</error-code>
      <location>/grails-errorhandler</location>
   </error-page>
   <error-page>
      <error-code>404</error-code>
      <location>/grails-errorhandler</location>
   </error-page>
</web-app>

grails.xml

<grails>
  <resources>
    <resource>grails.plugins.quartz.QuartzController</resource>
    <resource>DefaultQuartzConfig</resource>
    <resource>QuartzBootStrap</resource>
    <resource>grails.plugins.quartz.JobManagerService</resource>
    <resource>DefaultCacheConfig</resource>
    <resource>grails.plugin.cache.GrailsCacheAdminService</resource>
    <resource>grails.plugin.cache.CacheTagLib</resource>
    <resource>DefaultWebXmlConfig</resource>
    <resource>AssetPipelineBootStrap</resource>
    <resource>AssetUrlMappings</resource>
    <resource>asset.pipeline.AssetsController</resource>
    <resource>asset.pipeline.AssetProcessorService</resource>
    <resource>asset.pipeline.AssetMethodTagLib</resource>
    <resource>asset.pipeline.AssetsTagLib</resource>
    <resource>DefaultSecurityConfig</resource>
    <resource>grails.plugin.springsecurity.LoginController</resource>
    <resource>grails.plugin.springsecurity.LogoutController</resource>
    <resource>grails.plugin.springsecurity.SpringSecurityService</resource>
    <resource>grails.plugin.springsecurity.SecurityTagLib</resource>
    <resource>DbdocUrlMappings</resource>
    <resource>grails.plugin.databasemigration.DbdocController</resource>
    <resource>JQueryConfig</resource>
    <resource>JQueryPluginResources</resource>
    <resource>JQueryService</resource>
    <resource>JQueryResourceTagLib</resource>
    <resource>JQueryTagLib</resource>
    <resource>grails.plugin.redis.RedisTagLib</resource>
    <resource>grails.plugin.mail.MailService</resource>
    <resource>grails.plugin.mail.PlainTextMailTagLib</resource>
    <resource>BuildConfig</resource>  <!--conf 目录下的BuildConfig.groovy文件-->
    <resource>Config</resource>  <!--conf 目录下的Config.groovy文件-->
    <resource>DataSource</resource><!--conf 目录下的DataSource.groovy文件-->
    <resource>UrlMappings</resource>  <!--conf 目录下的UrlMappings.groovy文件-->
    <resource>com.xx.*</resource> <!---项目的包的路径,现在删除了,只留了一个,实际情况有很多很多-->
    </resources>
  <plugins>
    <plugin>QuartzMonitorGrailsPlugin</plugin>
    <plugin>QuartzGrailsPlugin</plugin>
    <plugin>ScaffoldingGrailsPlugin</plugin>
    <plugin>CacheGrailsPlugin</plugin>
    <plugin>WebxmlGrailsPlugin</plugin>
    <plugin>AssetPipelineGrailsPlugin</plugin>
    <plugin>SpringSecurityCoreGrailsPlugin</plugin>
    <plugin>SpringEventsGrailsPlugin</plugin>
    <plugin>P6spyGrailsPlugin</plugin>
    <plugin>Hibernate4GrailsPlugin</plugin>
    <plugin>DatabaseMigrationGrailsPlugin</plugin>
    <plugin>JqueryGrailsPlugin</plugin>
    <plugin>RedisGrailsPlugin</plugin>
    <plugin>RedisHibernateCacheGrailsPlugin</plugin>
    <plugin>MailGrailsPlugin</plugin>
    <plugin>SpringMobileGrailsPlugin</plugin>
    <plugin>FootstoneGrailsPlugin</plugin>
    <plugin>FootutilsGrailsPlugin</plugin>
  </plugins>
</grails>

3:我现在对于这些的了解不是很浅,有说的不对的,大家多指教。同时希望大家可以积极留言喔。才疏学浅的我发此贴算是抛砖引玉吧。希望大家喜欢grails。多多研究喔。

共有 人打赏支持
粉丝 0
博文 3
码字总数 2288
×
lerong_li
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: