Error while running spring mvc as standalone app using embedded jetty - spring-mvc

I have a main class to run spring mvc application as standalone application using jetty. I used maven-shade-plugin to generate the jar file.
I see the following error when i run the jar file
org.eclipse.jetty.servlet.ServletHolder$1: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 106; cvc-elt.1: Cannot find the declaration of element 'beans'.
My mvc-dispacher-servlet.xml looks like below
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
Can any one help me what is missing

It worked by adding the below in maven-shade-plugin configuration
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>

Related

Rest API for creating new workspace in Windchill

I want to create a workspace in Windchill calling Rest API from our web application. But no where to find such API end point in any of the Windchill Rest API documentation.
Is it possible to create workspace using rest API, if not is there any alternative way to achieve it.
On which Windchill version do you work?
When I don't find standard endpoints in the REST Services, I write them myself.
Since Windchill 11.1 I use Spring to create them.
For that you need an entry in codebase/WEB-INF/web.xml like:
<servlet>
<servlet-name>ConnectorName</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ConnectorName</servlet-name>
<url-pattern>/servlet/connector/*</url-pattern>
</servlet-mapping>
In the same folder you need a file named like the Servletname-servlet like ConnectorName-servlet.xml with following content:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop = "http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">
<context:component-scan base-package="packagename" />
<mvc:annotation-driven />
After this you can create a Spring RestController Class in the package defined above in component-scan.

Spring component scan error(schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd')

I have created a simple dynamic project without maven in eclipse. Only when I use tag context:component-scan, I face below error in Spring dispatcher file :-
schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root
element of the document is not .
Not sure from where version 4.3 is refered. I am using spring version 5.0.0.RELEASE and have added all jars in lib. Below is the content of spring dispatcher file :-
<?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.xsd">
<context:component-scan base-package="com.example.controller"/>
</beans>
I cant find fix for this issue. Suitable help will be appreciated.
There are many possibilities for this problem.
Initially you added ..../spring-beans-4.3.xsd and then you removed the version but error is still showing. It is because eclipse is reading from cache. Try removing cache in prefences->General->Network->cache
Even if you project is not maven, right click on the project go to properties and add "Maven Dependencies" in your Build Path. This resolved the similar error for me once.
If the above two does not work for you, try copy pasting this code
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd ">
<ctx:annotation-config></ctx:annotation-config>
<ctx:component-scan base-package="com.*"></ctx:component-scan>

schema not works when no internet connection

schema works fine during internet connection but it shows me following warning message when internet connection is off
No grammar constraints (DTD or XML Schema) referenced in the document.
i have used following schemas in spring-dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
what should i do to fix this problem?
First, you are using the schema which is a public URL. It is obvious trying to download from the internet. If you use relative path for the downloaded schema, it should work (but it is not recommended)
EDIT:
After going through some posts, I found this example.Hope it helps

Unable to locate Spring NamespaceHandler for XML schema namespace in OSGi (Karaf) with Web Application Bundle

I am trying to deploy the Web Application Bundle in karaf, but somehow Unable to locate Spring NamespaceHandler for XML schema namespace even after proper schema.
What could be the issue?
Karaf version : 3.0.0
Spring version : 3.2.x
Jetty version : 8.x
More details below:
Error while deploying:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema
namespace [http://www.springframework.org/schema/mvc]
Context class
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</context-param>
Context file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<mvc:resources mapping="/mydcos/**" location="file:/opt/mydocs/css/" />
Make sure you have spring-webmvc installed in Karaf. Spring DM is kinda legacy but MVC namespace handler is registered in same way as rest of them.

JNDI in spring MVC

Can someone please tell me how to configure JNDI name in SPRING MVC? I am using jboss version7.1.1 and DB is oracle 11g. I have defined the JNDI in jBoss server. How to mention the JNDI name in spring-servlet.xml? I have tried many options its not working. I am keep getting Name Not found exception.
<jee:jndi-lookup id="dataSource"
jndi-name="java:jboss/datasources/ExampleDS"
expected-type="javax.sql.DataSource" />
Where the value of jndi-name matches what you have configured in JBoss. You need to register jee namespace something like this:
<?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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

Resources