w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
NoClassDefFoundError in Tomcat but not in a Standalone application for a dynamically created java class
Maybe you are not dealing with the classloader chierarchy. Please read this enter link description here, Understanding The Tomcat Classpath - Common Problems And How To Fix Them and Tomcat Class Loader HOW-TO

Categories : Java

StandAlone Spring MVC Test framework
ofcourse it is possible to download it as a jar: http://mvnrepository.com/artifact/org.springframework/spring-test/3.2.4.RELEASE link jar to: http://repo1.maven.org/maven2/org/springframework/spring-test/3.2.4.RELEASE/spring-test-3.2.4.RELEASE.jar then you need to add is as library to your project which is different subject ( you probably should take a look what maven is ).

Categories : Eclipse

Spring, JPA, Hibernate, Tomcat: Unable to find persistence unit when loading Spring application context
As far I understood from my recent expirience of setting up 2 EntityManagerFactory in the same application - @PersistenceUnit(unitName="myPU") just doesn't work at all. I would suggest to inject EntityManager, not EntityManagerFactory. This is clear since you always know which EMF is used. Same for specifying right TransactionManager. Updated code of the service class: @Service public class CompetenceAreaManager { @PersistenceContext(unitName = "emf1") private EntityManager em; @SuppressWarnings("unchecked") @Transactional(transactionManager="transactionManager1", readOnly=true) public List<CompetenceArea> getCompetenceAreas() { List<CompetenceArea> competenceAreaList = null; Query q = em.createNamedQuery(CompetenceArea.FIND_ALL);

Categories : Java

Autowiring a Spring 3.2 standalone application fails
If it is running from eclipse and not running from the exported jar file, then it is a problem with the export In the export window there is a checkbox saying Add directory entries that should be checked for component-scan to work

Categories : Java

How do I create a spring .Net standalone object of type Int32 defined in the IOC context file?
Try this: <object id="MyInt" type="System.Int32" factory-method="Copy"> <constructor-arg index="0"> <value>123</value> </constructor-arg> </object>

Categories : C#

Is there a standard way to customize the deploy path in Spring Boot?
As it uses an embedded tomcat you should be able to add a /META-INF/context.xml to each application which specifies the path (at least this should work for a normal tomcat). That works for our normal embedded tomcat stuff, so I would expect it to work for Spring Boot as well.

Categories : Java

Spring and tomcat or Spring and Glassfish
It is perfectly possible to run a Spring application as a stand-alone Java application without any form of J2EE container at all. Assuming the application is some form of web based application then (unless you like re-inventing wheels) you will need a container and you have a choice of three categories: Servlet container (usually includes JSP & EL support). e.g. Apache Tomcat J2EE Web Profile container. e.g. Apache TomEE Full J2EE container. e.g. Apache Geronimo The options are listed in order of increasing functionality. Generally, I'd recommend pickign the class of container with the minimum functionality you need now and are likely to need in the short to medium term. I've listed the Apache containers as examples but there are plenty of others, both open and closed source. The

Categories : Spring

How to log unhandled exceptions using spring-ws
The reference documentation says: Endpoint exception resolvers are automatically picked up by the MessageDispatcher, so no explicit configuration is necessary. So just instantiate the class and set the property: <bean id="exceptionResolver" class="org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver"> <property name="warnLogCategory" value="com.mycompany.category"/> </bean>

Categories : Java

In Spring MVC, where to catch Database exceptions
1. I suspect you put your controller handler method as the transaction boundary, eg something like this: @RequestMapping @Transactional public String myHandler(..) { ... } A duplicate rows can only be detected once the update is synchronized into the database, this often occurs on transaction close if you use hibernate/jpa, hence you see as if it's coming from your controller Recall that @Transactional works by jdk proxy / aspect weaving. 3. The answer depends on your business requirement. What do you need to happen when a particular exception occur?

Categories : Hibernate

Handling exceptions in Spring MVC along with Rest API
I noticed this have been left for a month or so, so it might be old. But this article may help http://www.baeldung.com/2013/01/31/exception-handling-for-rest-with-spring-3-2/. The section 3.5 is probably what you are looking for, a custom Exception Resolver.

Categories : Spring

My eclipse tomcat server is stopping and gives these exceptions "java.net.SocketException" and "java.net.BindException"
Look at the last stack in the logs and you find the root cause of your problem: Address already in use: JVM_Bind It means there is already a process running and listening on the port you try to use. Most of the time, this error is caused by a previous run of your own program that didn't terminate (properly), or is still running. Take a look in your IDE to see if you don't have some running instance alive (and kill it). You can also take look at running process under Windows task manager (or any other equivalent utility on other platforms) and try to identify the process using the port. You may also have a tomcat running as a window service: in this case, just change the port use by your program to avoid conflicts.

Categories : Java

Spring REST API custom exceptions handling
The ServletRequestBindingException is a hint that something went wrong before the handler method of the controller. In this case some binding issue. Exception handlers annotated with @ExceptionHandler are only called when an exception is thrown within a controller handler method (@RequestMapping).

Categories : Spring

Spring MVC handle Exceptions and how to show in same view
You can use flash redirect attributes. @RequestMapping(value = "/administrator/users", method = RequestMethod.POST) public String adminAddUser(@ModelAttribute("user") @Valid User user, BindingResult bindingResult, Model model, RedirectAttributes redirectAttrs) { String redirectUrl = "/administrator/users"; try { userService.save(user); } catch (YourServiceException e) { redirectAttrs.addFlashAttribute("errorMessage", "error occured: " + e.getMessage()); redirectAttrs.addFlashAttribute("userObject", user); redirectUrl = "/administrator/users?form"; // If error - return to same view } return "redirect:" + redirectUrl; } @RequestMapping(value = "/administrator/users", params = "form", method = RequestMethod.GET, produces = "text/html") pub

Categories : Spring

Expecting database exceptions with JUnit, Spring and HIbernate
Use @Test(expected=DataIntegrityViolationException.class) You must use the top-most exception. In your expected you listed the cause not the top-most exception. OK, Wait a second. If you put the expected on the test, you should not have a try/catch in the test. Or if you do, you should re-throw the exception.

Categories : Java

Handling all listed exceptions but one with Spring's @ExceptionHandler annotation
I don't think there is a way to do that with the @ExceptionHandler annotation. One approach that should work is for you to provide an implementation of the HandlerExceptionResolver interface. In your implementation you could provide the code from your @ExceptionHandler methods and only execute it for the Exceptions that you wish to handle. I think for Spring MVC to pick-up your custom HandlerExceptionResolver, it will just need to be registered as a bean within your ApplicationContext.

Categories : Spring

How can I configure Spring 3 MVC to handle Errors similar to Exceptions?
The pattern we have used is to have a BaseController that all our Controllers extend using the following format to have specific errors mapped to specific HTTP status and a catch for more the most generic in Exception: @Controller public class BaseController { @ExceptionHandler (Exception.class) @ResponseStatus (HttpStatus.INTERNAL_SERVER_ERROR) public ModelAndView handleAllExceptions(Exception ex) { return new JsonError(ex.getMessage()).asModelAndView(); } @ExceptionHandler (InvalidArticleQueryRangeException.class) @ResponseStatus (HttpStatus.NOT_FOUND) public ModelAndView handleAllExceptions(InvalidArticleQueryRangeException ex) { return new JsonError(ex.getMessage()).asModelAndView(); } }

Categories : Java

Deploying Spring Web Applicaiton To JBoss WebApplicationContext Exceptions
Usually, the ContextLoaderListener from Spring is good to go. If you don't have any specific requirements, just use that one. All-in-all, it should look like this: <listener> <!-- Loads your Configuration Files--> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> If you need to have a listener that uses the Spring context, you could consider extending this class. Make sure that the contextInitialized() method calls the super implementation first (so that it can initialize the Spring context for you). Afterwards, it will be available through (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE). Your contextDestroyed() method, however, shoul

Categories : Java

Spring MVC + Eclipse + Tomcat
Go to your server.xml file. You will find your context root there. something like this <Context docBase="yourApp" path="/yourApp" reloadable="true" source="org.eclipse.jst.jee.server:yourApp"/></Host> Try loading localhost:8080/yourApp assuming you are running tomcat on port 8080.

Categories : Eclipse

Deploying spring project in tomcat
Have your Maven project compile for Java 1.6. Add this to your pom.xml: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build>

Categories : Java

Static methods with Spring MVC and tomcat
Its OK to use static methods if you know what you're doing. If in your static method you're using only local variables ( not fields in a class ) you should then be thread-safe too. Otherwise - it is up to you do handle the synchronization and locking to keep data consistent. Spring has a limitation that you cannot use static on setters of spring beans.

Categories : Spring

How to setup Spring Logs for Tomcat
Add this... log4j.appender.stdout.Target=System.out Also change console to stdout. See example log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Categories : Spring

favicon.ico not displaying in spring mvc 3.2.2 per Tomcat 7.0?
Make sure the icon is served, i.e. make a request to /favicon.ico and see if it renders. If it does, add this to your web.xml to make sure Tomcat sends the correct Content-Type with the response: <mime-mapping> <extension>ico</extension> <mime-type>image/x-icon</mime-type> </mime-mapping> Make sure <mvc:default-servlet-handler /> is present if you map the dispatcher servlet to /.

Categories : Java

Handling addtional exceptions and throwing custom error message in Spring security
You can extend AbstractHandlerExceptionResolver and handle your exception in this class. Code is not full, but you can understand the idea from that part. public class ExceptionResolver extends AbstractHandlerExceptionResolver { @Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { ModelAndView mav; if(ex instanceof YourException){ mav = loginController.showLoginPage(); mav.addObject("errorMessage","Some error message text."); \also you can change response code here or add some logic } else { \some another page } return mav; } Also add this to applicationContext.xml(or another file with your spring context configuration): <bean clas

Categories : Spring

Jersery ExceptionMapper does not intercept Exceptions thrown from Spring AspectJ annotated Aspects?
Ok I found the solution: Problem was that my ExceptionMapper was typed to map XBBridgeExceptions ( ExceptionMapper ). But Spring AOP aspect (RequestValidationAspect) throws UndeclaredThrowableException (which is a wrapper round XBBridgeException). Since UndeclaredThrowableException is a RuntimeExpcetion it was not intercepted by my mapper.Solution was to write another ExceptionMapper for UndeclaredThrowableException exceptions.

Categories : Spring

how to detect tomcat session expiration using spring
You can use a listener class to achieve this. Define a listener component as below: @Component public class AppLogoutListener implements ApplicationListener<SessionDestroyedEvent> { @Override public void onApplicationEvent(SessionDestroyedEvent event) { // from event you can obtain SecurityContexts to work with } } You need to define a session event publisher in your web.xml: <listener> <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> </listener> Here the HttpSessionEventPublisher publishes the session life cycle events whenever sessions are created and expired.

Categories : Spring

tomcat jdbc and spring version compatability
These two stack overflow links will solve your problems. org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class Spring Web App - CannotLoadBeanClassException caused by Java.lang.ClassNotFoundException

Categories : Java

Spring mvc application does not work as war in tomcat but it works well from IDE
The catalina.out log clearly shows that your @Controller is mapped to the path /contacts INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/contacts],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.apress.prospring3.ch17.web.controller.ContactController.list(org.springframework.ui.Model) However you are trying to access this handler with the path localhost:8080/contacts This will only work if you webapp is configured to have a context path of / and I'm pretty sure it isn't. Try using localhost:8080/[myapp]/contacts where [myapp] is the name of your application's folder in the webapps folder. See this answer on how to change that path.

Categories : Spring

Getting NullPointerException in Spring Batch when tomcat is shut down
I have not tried with spring quartz. However, normally while using Quartz, we shutdown the quartz gracefully. By gracefully, I mean here that I will shutdown the scheduler only after executing all my pending jobs(jobs which are executed currently but have not yet marked their completion). For graceful shutdowns, we pass attribute true while using method shutdown. Refer API here I am eager to know how spring quartz implementation does this.

Categories : Spring

How to avoid Classloader Leak with JPA, Hibernate and Spring on Tomcat
Configure a logging framework other than java.util.logging e.g. Logback. If no logging is configured at all, or if java.util.logging is configured, jboss logging will create a classloader leak via the JDK bug Level.known can leak memory. See the stack trace in the question where jboss logging creates the custom java.util.logging.Level.

Categories : Spring

Server to Client SSL Encryption w/o SSL Authentication - Tomcat & Spring
It seems you're mixing something up: Regular https includes encryption in both directions, and only a private key + certificate on the server side. Once a client requests resources through https, they get the answer encrypted. So you'll just need to enforce the https connection (e.g. by redirecting certain requests to https with no delivery of data through http) If you want client certificates, these are purely used for client authentication, so sharing a common client key/certificate with all possible clients will defeat this purpose. Having client keys/certs does not add any more encryption to your data transfer. Answering to your follow-up question in the comment: For https, the server keeps its private key, the public key is what is shared with the client. On typical https, the cli

Categories : Spring

Tomcat Context-Params ignored in Spring webapp when using PropertyPlaceholder
Spring uses a default property file unless the user-based property file is defined. If you want to control .properties file, please follow the instructions posted here. If you want to take advantage of application.properties there are two ways to do it. <!-- allows for ${} replacement in the spring xml configuration from the system.properties file on the classpath --> <util:properties id="appProperties" location="classpath:application.properties"/> <context:property-placeholder location="classpath:application.properties"/> util tag lets you to use a Property class to read the properties across your application. For example: @Autowired public MyPropertyReader(Properties appProperties) { String prop1 = appProperties.getProperty("my.address"); String pro

Categories : Spring

Tomcat Container Managed SSO Valve and Spring Security
You will be able to do it using J2eePreAuthenticatedProcessingFilter: http://static.springsource.org/spring-security/site/docs/3.2.x/reference/htmlsingle/#d4e2766 Please note: When Tomcat SSO is configured it provides Java EE authentication for a web application. It means that for an application is transparent if it was authenticated by form authentication or for Tomcat SSO. Finally it is Java EE authentication. So, you need to use J2eePreAuthenticatedProcessingFilter to be able to use Java EE authentication provided by Tomcat.

Categories : Java

How to use AspectJ load time weaving with Tomcat? (without Spring)
Well, probably my answer is too late, but I hope it will help others. Some time ago I faced the same problem. Two years were passed, so I use Tomcat 7 and AspectJ 1.8.8 now. So, first of all you don't need to change system class loader. There is java agent feature since Java 5, so AspectJ now uses it for load time weaving. For Tomcat just add this to your %CATALINA_HOME%setenv.bat: set JAVA_OPTS=-javaagent:c:path oaspectjweaver.jar set CLASSPATH=%CLASSPATH%;c:path oyouraspect Enjoy! :)

Categories : Tomcat

Redirect HTTP to HTTPS in Spring Security or Tomcat
I configured the redirection from HTTP(port 80) to HTTPS(port 443) within server.xml as <Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="443"/>

Categories : Tomcat

spring mvc - error in server start - apache tomcat
You are missing the jar containing the class org.springframework.web.context.request.async.CallableProcessingInterceptor. This is in spring-web-XXX.jar, where XXX is your version. Go find it online (maven repo) and add it to lib.

Categories : Java

Spring mvc application does not start in Tomcat when i add global-method-security
I think you can try to add security to schemaLocation on applicationContext.xml. Something like this: xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> Then I think it can read your xml right. EDIT: In your case, I think you can use the same schemaLocation from spring-security.xml xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"

Categories : Spring

Spring autowire stops working for classes on the Tomcat classpath
Autowiring can fail due to incompatible types (e.g. classes loaded in multiple classloaders). Since you already place the JAR in tomcat's boot classpath, it must be visible to the webapp as well without you having to place the JAR in WEB-INF/lib. You can make the dependency scope provided to not have Maven place it in WEB-INF/lib.

Categories : Spring

Jsp page is not accepting css rules under Spring Mvc project (running on Tomcat 7)
You have to change something so the css file gets loaded. Tomcat can't find it at "../../css/mystyles.css" (which you show as being http://localhost/css/mystyles.css" in firebug's net tab) so the URL in the tag is either wrong or Tomcat is set up somehow wrong. Hint: You can enter the URL for a css file in the browser address bar to try various things more easily as you change the Tomcat config or load files.

Categories : Spring

Vaadin 7.1 + Spring-Security Integration running in Tomcat Server
You should have a look on this GitHub project. This is a Vaadin 7.1 + Spring 3.1.2.RELEASE + Spring-Vaadin integration 2.0.1 project. There is also a Jetty plugin inside, but you can run/deploy it also in tomcat without problems.

Categories : Spring

How to change the context path of a Spring MVC application deployed in TOMCAT 6.0
When adding a context.xml to the META-INF directory of the web application you should only need to specify the path, the other fields are deducted from where the application is deployed. The docBase is only needed if you specify the path inside the hosts or server.xml. <?xml version="1.0" encoding="UTF-8"?> <Context path="/DS" reloadable="true" /> So basically the above should be enough, make sure that you don't have any leftovers from your previous attempts as that might influence how this works. (Although I believe this one should take precedence over the others).

Categories : Maven



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.