Hi I'm using spring and I want to include a css file.
I've created a folder resources/mytheme/css/signing.css under webapp.
My dispatcher servlet looks like this:
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.springapp.mvc"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/mytheme/" />
</beans>
In my jsp file I reference to the css file like this:
<link href="${pageContext.request.contextPath}/resources/css/signing.css" rel="stylesheet" >
When I surf to the page I always get a 404 and The requested resource is not available.
Someone who can help me?
I fixed the problem by adding this to my web.xml
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
This makes my resource folder available.
Related
I have tried Yii2 Code Sniffer Git Hook by RichWeber and squizlabs/PHP_CodeSniffer.
I cant not install and manage any thing properly.There i have added some global composer files and some vendor/bin/.
I have no idea at all that how i can configure it and how i can run it useful in my project.
I have use phpcs and yii2 code standeard add this to composer.json
"yiisoft/yii2-coding-standards": "2.*",
"squizlabs/php_codesniffer": "^3.0#dev"
And add phpcs.xml.dist in root directory and add this standards
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Yii2">
<description>Yii 2 Web Application Framework Coding Standard</description>
<rule ref="PSR2">
<!-- Property names MUST start with an initial underscore if they are private. -->
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
<!-- Opening parenthesis of a multi-line function call must be the last content on the line. -->
<!-- Closing parenthesis of a multi-line function call must be on a line by itself. -->
<!-- Only one argument is allowed per line in a multi-line function call. -->
<exclude name="PEAR.Functions.FunctionCallSignature"/>
<!-- We don't have line length (line width) limits. -->
<!--<exclude name="Generic.Files.LineLength"/>-->
<!-- CASE keyword must be indented 4 spaces from SWITCH keyword. -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration"/>
</rule>
<!-- Property declaration rules. -->
<!-- TODO: -->
<!-- Function call signature. -->
<!-- TODO: -->
<!-- Switch declaration. -->
<!-- TODO: -->
<!-- ... other Yii2 specific rules. -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<!-- If string doesn't contain variables or single quotes, use single quotes. -->
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired"/>
<!-- Replaces Yii2_Sniffs_Files_SpacesAroundConcatSniff -->
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1" />
<property name="ignoreNewlines" value="true" />
</properties>
</rule>
<!-- Replaces Yii2_Sniffs_Properties_PrivatePropertiesUnderscoreSniff -->
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/1008 -->
<rule ref="Squiz.ControlStructures.ControlSignature">
<properties>
<property name="requiredSpacesBeforeColon" value="0" />
</properties>
</rule>
<!-- line length -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120" />
<property name="absoluteLineLimit" value="120" />
</properties>
</rule>
<rule ref="Generic.PHP.Syntax"/>
<!-- Ignore for migrations. -->
<!-- Ignore missing namespace for migrations -->
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>m\d{6}_\d{6}_.+\.php$</exclude-pattern>
</rule>
<!-- Ignore camel caps format for class name of migrations -->
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
<exclude-pattern>m\d{6}_\d{6}_.+\.php$</exclude-pattern>
</rule>
<!-- Ignore for tests. -->
<!-- Ignore method name prefixed with underscore to indicate visibility -->
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<exclude-pattern>tests?/*(Cest|Test).php$</exclude-pattern>
</rule>
<!-- Ignore declare new symbols and execute logic with side effects same file -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>/tests?*/_bootstrap.php$</exclude-pattern>
<exclude-pattern>/web/(index|index-test).php$</exclude-pattern>
</rule>
<exclude-pattern>*/i18n/data/*</exclude-pattern>
<exclude-pattern>*/views/errorHandler/*</exclude-pattern>
<exclude-pattern>*/requirements/*</exclude-pattern>
<exclude-pattern>ProfileTarget.php</exclude-pattern>
</ruleset>
Now use these command to test each of the folder standard like i am testing backend like this
vendor/bin/phpcs --encoding=utf-8 --extensions=php backend
and to fix these error run this command
vendor/bin/phpcbf --encoding=utf-8 --extensions=php backend
Note: You have to remove parse and syntax error yourself.
I have spent all day trying to solve the logging problem I'm having with log4j in a webapp. No matter what I do, I cannot get rid of the following:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Just to be clear, I have read all of the articles here on Stack Overflow addressing this issue. I've read the log4j manual. I've been through a dozen different tutorials. I've tried the properties approach and the XML approach (log4j.properties and log4j.xml, respectively). Also, I have confirmed that the log4j.xml file is being read. Aside from the fact that the server tells me so during startup, I can influence the level of feedback through the .xml file. So, yes, the log4j.xml file is in the CLASSPATH.
I know I'm missing something simple and fundamental. Below are the relevant files:
LOG4J.XML (/WEB-INF):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
</layout>
</appender>
<!-- Application Loggers -->
<logger name="com.tiersoftinc.testlog">
<level value="info" />
</logger>
<!-- 3rdparty Loggers -->
<logger name="org.springframework.core">
<level value="info" />
</logger>
<logger name="org.springframework.beans">
<level value="info" />
</logger>
<logger name="org.springframework.context">
<level value="info" />
</logger>
<logger name="org.springframework.web">
<level value="info" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
and WEB.XML (/WEB-INF):
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters, and the applicationContext.xml file -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
/WEB-INF/spring/app-context.xml
</param-value>
</context-param>
<!-- Logging listener -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
and APP-CONTEXT.XML (/WEB-INF/spring):
<?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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- Activates various annotations to be detected in bean classes -->
<context:annotation-config />
<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
For example #Controller and #Service. Make sure to set the correct base-package -->
<context:component-scan base-package="com.tiersoftinc.gridlab3" />
<!-- Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only! -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Imports datasource configuration -->
<import resource="app-context-mongo.xml"/>
</beans>
and APP-CONTEXT-MONGO.XML (/WEB-INF/spring):
<?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:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<!-- Activate Spring Data MongoDB repository support -->
<mongo:repositories base-package="com.tiersoftinc.gridlab3.repository" />
<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/spring/database.properties</value>
</list>
</property>
</bean>
<!-- MongoDB host -->
<mongo:mongo host="${mongo.host.name}" port="${mongo.host.port}"/>
<!-- Template for performing MongoDB operations -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"
c:mongo-ref="mongo" c:databaseName="${mongo.db.name}"/>
<!-- Service for initializing MongoDB with sample data using MongoTemplate -->
<bean id="initGridLab3Service" class="com.tiersoftinc.gridlab3.services.InitGridLab3Service" init-method="init"/>
</beans>
and, finally, ROOT-CONTEXT.XML (/WEB-INF/spring):
<?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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<context:annotation-config />
</beans>
What am I missing?
Thank you.
Have you tried this?
<logger name="org.springframework.web">
<level value="info" />
<appender-ref ref="console" />
</logger>
Put these lines in the beginning of your web.xml:
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:/main/resources/log4j.xml</param-value>
</context-param>
When i modified my app.config to include the ReflectSoftware logging infomration, Ninjatrader crashed. Can you point out where I did not configure it correctly?
?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>
<configSections>
<section name="insightSettings" type="ReflectSoftware.Insight.ConfigurationHandler,ReflectSoftware.Insight"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
In order to recieve location information, you must ensure the layout has the parameter ${callsite} and all
its properties set accordantly.
-->
<extensions>
<add assembly="ReflectSoftware.Insight.Extensions.NLog"/>
</extensions>
<targets>
<target name="ReflectInsight"
xsi:type="ReflectInsight"
instanceName="nlogInstance1"
displayLevel="true"
displayLocation="true"
layout="${callsite:className=true:fileName=true:includeSourcePath=true:methodName=true}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="ReflectInsight" />
</rules>
</nlog>
</configuration>
fixed by moving the xml fragment after Config sections
SuppressionFilter is not ignoring the files which are given in suppressions.xml
In checkstyle.xml,
<module name="Checker">
<module name="SuppressionFilter">
<property name="file" value="/home/svn/testrepo/scripts/suppressions.xml"/>
</module>
<module name="TreeWalker">
....
</module>
In suppressions.xml (which is in /home/svn/testrepo/scripts),
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="."
files="Constants.java" />
</suppressions>
Also, tried with the below one:
<suppressions>
<suppress files="Constants\.java" checks="[a-zA-Z0-9]*"/>
</suppressions>
Also, tried with:
<suppressions>
<suppress checks=".*"
files="Constants.java" />
</suppressions>
None of the options are working. Can anybody have answers on this? Please help me out.
Assuming you configure the filter using:
<module name="SuppressionFilter">
<property name="file" value="suppressions.xml"/>
</module>
Then an example content of suppressions.xml could be:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress checks="." files="[\\/]SoapAdapter\.java$"/>
</suppressions>
This will then suppress all checks for the files named SoapAdapter.java. Note that [\\/] is just a regular expression to handle file names under Unix (which use /) and Windows (which use \).
Also recommend reading the Checkstyle documenation on the subject at http://checkstyle.sourceforge.net/config.html.
just add ${config_loc} in front of value as described in the official documentation
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppressions.xml"/>
</module>
Let me preface this question by saying I've exhausted Google, or at least what I've been trying to search for. "log4j threshold", "log4j threshold category", "log4j appender threshold category", etc. But I really don't understand the results I'm getting back from Google.
This is the full configuration I've been given. I can't figure out how to modify it to suit my needs.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: jboss-log4j.xml 62403 2007-04-18 15:26:43Z dimitris#jboss.org $ -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->
<category name="com.arjuna">
<priority value="FATAL"/>
</category>
<category name="com.sun.facelets">
<priority value="ERROR"/>
</category>
<category name="jacorb">
<priority value="FATAL"/>
</category>
<category name="javax.enterprise.resource">
<priority value="WARNING"/>
</category>
<category name="javax.enterprise.resource.webcontainer.jsf">
<priority value="WARNING"/>
</category>
<category name="org.apache">
<priority value="FATAL"/>
</category>
<category name="org.hibernate">
<priority value="FATAL"/>
</category>
<category name="org.jboss">
<priority value="INFO"/>
</category>
<category name="org.jboss.ejb3.EJB3Deployer">
<priority value="WARNING" />
</category>
<category name="org.jboss.ejb3.JmxKernelAbstraction">
<priority value="WARNING" />
</category>
<category name="org.jboss.management">
<priority value="FATAL"/>
</category>
<category name="org.jboss.serial">
<priority value="FATAL"/>
</category>
<category name="org.jboss.wsf.framework">
<priority value="FATAL"/>
</category>
<category name="org.jgroups">
<priority value="FATAL"/>
</category>
<category name="org.quartz">
<priority value="FATAL" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
I don't understand how the appender's "threshold" level interacts with the categories. See, I only want com.foo.bar messages to show on the console. But it seems like I'm getting a lot more than that, for instance, org.jboss.wsf.framework is dumping out DEBUG messages, even though I have a category with a name that matches it and set to FATAL.
I'm certain I'm manipulating the correct config file, as jboss reports it's reloading the config after I change it. So how do I set the category/threshold levels right? What's the difference between the threshold and category?
Example output (snipped). Why does quartz show up on the console when I have it set to FATAL?
2009-06-22 00:58:37,666 INFO [org.quartz.plugins.history.LoggingJobHistoryPlugin] Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer execution complete at 00:58:37 06/22/2009 and reports: null
2009-06-22 01:08:37,669 DEBUG [org.quartz.simpl.SimpleJobFactory] Producing instance of Job 'JobInitializationPlugin.JobInitializationPlugin_jobInitializer', class=org.quartz.jobs.FileScanJob
2009-06-23 15:44:17,790 INFO [org.jboss.wsf.stack.jbws.NativeServerConfig] 3.0.5.GA
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEJB
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEndpointAPI
To answer the specific question of why does Quartz show up on the logging, you would have to change the Quartz configuration as follows:
<category name="org.quartz" additivity="false">
<priority value="FATAL" />
</category>
The additivity attribute tells log4j to override the root setting and use this only for org.quartz.
In a previous version of the question you stated you only wanted those messages from those classes turned on, to do that you have to start with configuring the priority in the root element to fatal (or even NO) and then it will only log those packages/classes that you turn on explicitly.
To answer your question about how threshold interacts with category, basically think of it is as a publish/subscribe. The category sets what is published by the logger, the threshold sets the subscription level of the appender.
This is complicated slightly be the fact that category is not a single thing, but rather a hierarchy, so the fact that you set the publishing level on one category isn't the whole story. It may be overridden in the hierarchy, as it was in your case.
Move "<appender-ref ref="CONSOLE"/>" from <root> to <category name="com.foo.bar">.
I.e.:
<category name="com.foo.bar">
<priority value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
</category>
<root>
<appender-ref ref="FILE"/>
</root>
With the config that you show the console shouldn't get any debug messages so check if any other config could be used or if some code is programatically changing the config.